mahesh
BAN USER
Comments (3)
Reputation -5
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
-1
of 1 vote
k=0;j=0;i=0;
while(k<K)//K is the K mentioned in the question
{
sum= a[i]+b[j]; //calculate sum with current i and j, it will be the next smallest
k++;
//now we need to know whether to increment i or j
//This will depend on (a[i]+b[j+1]) and (a[i+1]+b[j])
if ( a[i]+b[j+1] < a[i+1]+b[j] ) //incrementing index of b takes us to the next smallest sum
j++;
else
i++
}
return sum;
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
bug1: i%(3+5) should be i%15
- mahesh December 20, 2013bug2: i%15 should be before i%3 and i%5 because any number that is divisible by 15 is automatically divisible by 3 and 5. So the specialized case need to be first.
bug3:??