Data Structures & AlgorithmsVery hardProduct-company placement

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

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

Correct answer: B. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic