Palindrome Partition | Backtracking | C++ Solution
Palindrome Partition, is a Backtracking related problem and in this post we will see how we can solve this challenge in C++
Given a string s, partition s such that every string of the partition is a palindrome.
Return all possible palindrome partitioning of s.
For example, given s = "aab", Return
[ ["a","a","b"] ["aa","b"], ] Ordering the results in the answer : Entry i will come before Entry j if : len(Entryi[0]) < len(Entryj[0]) OR (len(Entryi[0]) == len(Entryj[0]) AND len(Entryi[1]) < len(Entryj[1])) OR
(len(Entryi[0]) == len(Entryj[0]) AND … len(Entryi[k] < len(Entryj[k])) In the given example, ["a", "a", "b"] comes before ["aa", "b"] because len("a") < len("aa") check if it is palindrome or not using backtracking when there is only element then it is a palindrome check for each substring if they form a palindrome or not if it forms a palindrome then check for the rest using recursion driver function
Please check the main.cpp snippet for the solution.
This solution originally posted at: Github by @susantabiswas
Comments
Leave a comment
You are not LoggedIn but you can comment as an anonymous user which requires manual approval. For better experience please Login.