Data Structures & AlgorithmsHard

How many contiguous subarrays of [1, 2, 1, 3, 4, 2, 3] contain no repeated value?

  1. A. 7
  2. B. 14
  3. C. 12
  4. D. 19

Correct answer: D. 19

A subarray has no repeats exactly when its length equals the number of distinct values in it. Counting one subarray per right end ignores the earlier valid starts, and the at-most-2 count mixes in windows that contain repeats.

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

Exams that ask this topic