Understanding the bottom up solution to the palindrome partitioning problem
To solve the palindrome partitioning problem using a bottom-up dynamic programming approach, we fill a table iteratively beginning from the smallest subproblems and building towards the final answer. As with any bottom-up solution, we process subproblems in an order that guarantees every result we depend on has already been computed and stored before we need it.
The bottom up solution
We solve this problem in two stages. First, we precompute a 2D table that records, for every pair of indices (i, j), whether the substring s[i...j] is a palindrome. Then, we use this table to build a 1D array that records the minimum number of cuts needed for each substring of the form s[i...n-1], that is, each substring that starts at some index i and extends all the way to the last index of the string.
Liking the course? Check our discounted plans to continue learning.