Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: A binary search over the sorted array [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] looks for the value 12 which is absent. Using the standard lower-bound variant, what index is returned?

  1. A. 5
  2. B. 7
  3. C. 13
  4. D. 6

Correct answer: D. 6

Lower bound returns the first index whose value is ≥ 12, which is 13 at index 6. The largest smaller element is at 5, a 1-based answer gives 7, and 13 is the value rather than the index.

More Coding Interview Problems questions

Exams that ask this topic