Data Structures & AlgorithmsHardTCS Digital · Infosys SP

A peak is an element larger than its neighbours (array ends count as −∞). Binary search runs on [43, 46, 49, 14, 48, 18, 24, 47, 28]: while lo < hi, mid = (lo + hi) // 2; if a[mid] < a[mid + 1] then lo = mid + 1 else hi = mid. Which index does it return?

  1. A. 7
  2. B. 3
  3. C. 2
  4. D. 4

Correct answer: C. 2

The search always moves towards a rising neighbour, so it ends on a local peak — index 2 (value 49). Peaks here: 2, 4, 7.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic