Data Structures & AlgorithmsHard

How many positions i in 1 1 2 2 3 1 4 2 satisfy: A[i] equals the number of DISTINCT values among A[0..i−1] (the elements strictly before i)?

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

Correct answer: B. 2

For each index count the distinct values strictly before it and compare that count with the element. Counting all earlier elements, including the current element in the set, or adding one each measure a different thing.

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

Exams that ask this topic