Amazon Interview Question
Software Engineer / Developersgenerally we talk about worst case complexity and o(log(n!)) is a very complex algorithm.
simple one can be like this with order o(n).
assuming increasing order of list.left anr right are leftmost and rightmost indices.
if((left+right)<sum)
left++;
else if((left+right)>sum)
right--;
else return(left,right)
The code is
/***
- Lord Darth Plaguies June 30, 2009~/Codes$ ./a.out 15 14 13 12 11 8 3 1 24
13(2) + 11(4) = 24
~/Codes$ ./a.out 15 14 13 12 11 8 3 1 4
3(6) + 1(7) = 4
*/