Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

In how many ways can the string "aabaab" be split into one or more contiguous pieces so that every piece is a palindrome? (Each split is counted once, and a single letter is a palindrome.)

  1. A. 11
  2. B. 8
  3. C. 6
  4. D. 9

Correct answer: B. 8

Let ways[j] be the number of valid splits of the prefix of length j, and add ways[i] for every i where s[i..j−1] is a palindrome. Counting the minimum number of cuts answers a different question.

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

Exams that ask this topic