Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B

The sorted array [1, 2, 4, 5, 9, 10] is given. What is the smallest positive integer that does NOT appear in it?

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

Correct answer: D. 3

The first gap in the sorted array is where a[i] − (i + 1) first becomes positive; the missing value is then i + 1. Using the length plus one assumes the array is a permutation of 1..n, which it is not.

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

Exams that ask this topic