Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: A sorted array [2, 3, 5, 7, 11, 13, 17, 19] is searched for 11 using binary search with mid = (lo + hi) // 2 over the inclusive range [0, 7]. What is the index where 11 is found?

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

Correct answer: D. 4

The midpoint of [0, 7] is 3 (value 7), so the search moves right; the next midpoint of [4, 7] is 5 (value 13), so it moves left and finds 11 at index 4.

More Coding Interview Problems questions

Exams that ask this topic