Data Structures & AlgorithmsVery hard

How many contiguous subarrays of 2 1 3 2 1 3 3 2 contain EVERY distinct value that appears in the whole array?

  1. A. 19
  2. B. 36
  3. C. 17
  4. D. 3

Correct answer: A. 19

All values {1, 2, 3} must be present; for each start, the valid ends begin where the last missing value first appears, giving 19 of the 36 subarrays. 17 is the complement (subarrays missing a value), and 3 is the number of distinct values.

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

Exams that ask this topic