Data Structures & AlgorithmsVery hardCodeforces Div2 C · TCS NQT

The sorted array [2, 3, 4, 7, 11] contains some positive integers. What is the 5th positive integer that does NOT appear in this array?

  1. A. 9
  2. B. 10
  3. C. 5
  4. D. 1

Correct answer: A. 9

Missing numbers are 1, 5, 6, 8, 9, ..., so the 5th is 9; binary search on a[mid] − (mid + 1) finds the spot. Adding k to the array length (5 + 5) gives 10, 5 is k itself, and 1 is only the first missing number.

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

Exams that ask this topic