• Customer Support: admin@thealgorists.com
  • Feedback: We are listening to your every feedback, and taking action to constantly improve your learning experience. If you have any feedback, please use this form: https://thealgorists.com/Feedback.
  • If you are a student, email to admin@thealgorists.com to get special student discount.

Problem Statement:

Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.
A palindrome string is a string that reads the same backward as forward.

Example 1:
Input: s = "aab"
Output: [["a","a","b"],["aa","b"]]

Example 2:
Input: s = "a"
Output: [["a"]]


Having a strong grip on Backtracking Template is an absolute necessity to solve this problem, if you are new to Backtracking.

We need to cut the string at all possible places to form the first palindromic substring and for each of this palindromic substring we explore the rest of the given string to look for other palindromic substrings.

So here the candidates would be indices in the given string that would give us a palindromic substring starting from the start index, so
beg = start index
and end = candidate index

Let's look at the code below and the inline comments for better understanding of our algorithm. The code adheres to our Backtracking Template.

This is a Premium content. Please subscribe to access the code.
After subscribing please come back and refresh this page.

Don't forget to take in-depth look at the other backtracking problems because that is what would make you comfortable with using the backtracking template and master the art of Backtracking:

The above content is written by:

Abhishek Dey

Abhishek Dey

A Visionary Software Engineer With A Mission To Empower Every Person & Every Organization On The Planet To Achieve More

Microsoft | University of Florida

View LinkedIn profile

If you have any feedback, please use this form: https://thealgorists.com/Feedback.

Subscribe to Our Youtube Channel

Follow Us On LinkedIn