My Google Coding Interview Question | by William Wen | CodeX | May, 2022 | Medium
Given a positive sorted array a = [ 3, 4, 6, 9, 10, 12, 14, 15, 17, 19, 21 ];
Define a function f(a, x) that returns x, the next smallest number, or -1 for errors.
i.e.
f(a, 12) = 12
f(a, 13) = 12
Why Binary Search?
Binary search is one of the most difficult “simple” coding problems. The algorithm looks trivial, but it’s a devil to implement. Jon Bentley, a former CMU professor, wrote in his book Programming Pearls that only 10% of professional programmers are able to implement it correctly, including PhD students.
May 11, 2022 at 8:58:40 AM EDT
*
FILLER