Data Structures & AlgorithmsHard

How many positions i in 0 1 2 2 3 1 4 satisfy: the value A[i] equals the number of elements BEFORE position i that are strictly smaller than A[i]?

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

Correct answer: D. 5

For each position count the earlier elements that are strictly smaller and compare that count with the value itself. Allowing equal earlier elements, counting later elements, or a plain tally each give other numbers.

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

Exams that ask this topic