Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B

How many subarrays of [1, 2, 1, 2, 2, 1] read the same forwards and backwards (as sequences of values)?

  1. A. 21
  2. B. 8
  3. C. 10
  4. D. 6

Correct answer: C. 10

Six single elements, plus [2,2], [1,2,1], [2,1,2] and [1,2,2,1]: 10. Expanding only around odd centres misses the even ones (8), 6 counts single elements only and 21 counts all subarrays.

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

Exams that ask this topic