Data Structures & AlgorithmsModerateTCS CodeVita · Codeforces Div 2

What is the smallest positive integer missing from the array [3, 4, −1, 1]?

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

Correct answer: C. 2

1 is present, so 2 is the first gap. Cyclic sort places each value v at index v − 1 in O(n) time with O(1) extra space, and the answer is the first index holding the wrong value.

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

Exams that ask this topic