Enkesh Gupta
BAN USER
Questions (3)
Comments (5)
Reputation 55
- 2of 2 votes
AnswersGiven an Integer where only one Bit is set, Identify that Bit in O(1).
- Enkesh Gupta in United States| Report Duplicate | Flag | PURGE
Deshaw Inc
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
By identify, I meant to get the Position of Set Bit
- Enkesh Gupta July 12, 2015Comment hidden because of low score. Click to expand.
0
of 0 vote
Got it,
Thanks for your detailed explanation. :)
Comment hidden because of low score. Click to expand.
0
of 0 vote
Your code will produce Incorrect o/p, if it's being used for more than 1 test cases.
While returning true, Matrix needs to be updated(mat[ll][rr]=c).
Comment hidden because of low score. Click to expand.
0
of 0 vote
Efficient solution using Pair in c++
int find(int *arr,int *dep, int n){
pair<int,int> p[2*n];
int i=0,j;
for(i=0;i<n;i++){
p[2*i]=make_pair(arr[i],1);
p[2*i+1]=make_pair(dep[i],-1);
}
sort(p,p+2*n);
int tmp=0,ans=INT_MIN;
for(j=0;j<2*n;j++){
tmp+=p[j].second;
ans=max(tmp,ans);
}
return ans;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
I guess it won't meet the condition of O(1). As log(n) would also follow a series at the back
- Enkesh Gupta July 12, 2015