Data Structures & AlgorithmsHardTCS NQT · Infosys

How many non-empty contiguous subarrays of [2, 2, 3, 3, 3, 2] consist of one repeated value only?

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

Correct answer: B. 10

Each maximal run of length L contributes L(L+1)/2 subarrays. A run of three 3s gives six, not three.

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

Exams that ask this topic