Data Structures & AlgorithmsVery hard

How many contiguous subarrays of 1 2 3 1 2 4 1 contain EXACTLY three distinct values?

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

Correct answer: D. 9

Exactly three distinct values is the difference between at-most-three and at-most-two counts. Using at-least-three, exactly-two, or restricting the length to three each changes the total.

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

Exams that ask this topic