Number of Ways to Partition a String into a Palindromes | Dynamic Programming

Prereq: Palindrome Counting

The problem is exactly the same as in Palindrome Partitioning except instead of outputting every possible palindrome, we instead ask you to simply output the number of possible partitions. The string size can be up to 2000 characters in length. The number will be guaranteed to fit into an int.


Example 1:

Input: aab
Output: 2

Try it yourself



Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions