Data Structures & AlgorithmsVery hardProduct-company placement

What is the minimum number of cuts needed to split 'abacdcab' into pieces that are all palindromes?

  1. A. 1
  2. B. 3
  3. C. 2
  4. D. 0

Correct answer: A. 1

cuts(i) = min over palindromic s[j..i−1] of cuts(j) + 1 gives 1. Greedily taking the longest palindrome from the left needs 3 cuts here.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic