Data Structures & AlgorithmsHardProduct company OA

The sorted array [3, 4, 7, 10, 11] contains some positive integers. What is the 4th positive integer MISSING from it?

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

Correct answer: A. 6

Missing positives in order: 1, 2, 5, 6, 8, 9, … → the 4th is 6. In O(log n): before a[i] there are a[i] − (i + 1) missing numbers (2, 2, 4, 6, 6), so the answer lies between 4 and 7: 4 + (4 − 2) = 6. '8' counts missing numbers after 7 only.

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

Exams that ask this topic