Amazon Interview Question
Software Engineer / DevelopersTo find two nos in array whose sum is equal to given no:
1) If array is sorted the your method can give result in O(n) else it will require O(nlgn) + O(n)
2) If memory is not the constraint then add each element of array in hasttable in O(n). In other O(n) find the two nos. Total : O(n) + O(n)
1) Divide 9 marbles into group of 3, and then select any two group and check their weight. If either of is heavier, then select that group or select third group. Now select any two marbles out of this group of three and check their weight. By this procedure you need to compare just twice.
- Anonymous October 18, 2008