Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

What is the minimum number of cuts needed to split "abbacdcdc" into pieces that are each a palindrome?

  1. A. 8
  2. B. 6
  3. C. 4
  4. D. 7

Correct answer: D. 7

Let pal[i][j] say whether s[i..j] is a palindrome, and cut[j] = min over i of cut[i−1] + 1 whenever s[i..j] is a palindrome (with cut = 0 if the whole prefix is one palindrome). Cutting between every letter is the trivial upper bound, which is n − 1.

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

Exams that ask this topic