Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: The sorted array [1, 4, 4, 9, 12, 12, 15, 20] (0-indexed) may contain repeated values. Using a lower-bound search, which returns the first index whose value is at least 12, what index is returned?

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

Correct answer: D. 4

The lower bound is the first index holding a value at least 12, here the first occurrence of 12. Using bisect_right returns the index after the last 12 instead.

More Coding Interview Problems questions

Exams that ask this topic