Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many contiguous subarrays of [1, 1, 2, 2, 2, 3] contain only one distinct value?

  1. A. 10
  2. B. 11
  3. C. 12
  4. D. 14

Correct answer: A. 10

Runs of equal values of length L give L(L+1)/2 subarrays: runs 2, 3 and 1 contribute 3, 6 and 1.

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

Exams that ask this topic