Data Structures & AlgorithmsHard

How many contiguous subarrays of length at least 2 of 1 1 2 2 2 3 1 1 1 1 consist of ONE repeated value?

  1. A. 23
  2. B. 11
  3. C. 10
  4. D. 20

Correct answer: C. 10

Inside a run of L equal values, every subarray of length at least 2 is constant, giving C(L,2) blocks per run. Allowing two distinct values, adding one, or including singletons changes the total.

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

Exams that ask this topic