mitesh.pant
BAN USER
Comments (3)
Reputation -30
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
-5
of 5 vote
What is the expected complexity.With O(n) complexity this is a very easy question. Check for all the numbers in the range [min,max] , if the number lies between
300 -310 or 400-420 or 500-515.
Before getting inside the loop we may wnt to check if
300 <= min and max >= 310
or
400 <= min and max >= 420
or
500 <= min and max >= 515
In this case all the numbers can be generated and we need not to get inside the loop
Comment hidden because of low score. Click to expand.
-1
of 1 vote
Since both are sorted array,The first element of both the array will be minimum. So the sum a[0]+b[0] will be less than any of other a[i]+b[j]
so the answer is straight
A[0] + B[0]
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Create an array say P[].
- mitesh.pant December 24, 2013for(i=0;i<len(w);i++)
{
n = w[i]*10;
while(n>0)
{
push(i,P);
n--;
}
}
// Now P will have [0,0,0,1,1,1,1,1,2,2]
random = rand(P);
print A[random];