From 2438624f7358604ac0452ce19f92ea6948ef152d Mon Sep 17 00:00:00 2001 From: Jethendra-17 <146614641+Jethendra-17@users.noreply.github.com> Date: Wed, 25 Oct 2023 22:32:06 +0530 Subject: [PATCH] Create Palindromic Partitioning.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string. Example 1: Input: str = "ababbbabbababa" Output: 3 Explaination: After 3 partitioning substrings are "a", "babbbab", "b", "ababa". Example 2: Input: str = "aaabba" Output: 1 Explaination: The substrings after 1 partitioning are "aa" and "abba". Your Task: You do not need to read input or print anything, Your task is to complete the function palindromicPartition() which takes the string str as the input parameter and returns the minimum number of partitions required. Expected Time Complexity: O(n*n) [n is the length of the string str] Expected Auxiliary Space: O(n*n) Constraints: 1 ≤ length of str ≤ 500 --- Palindromic Partitioning.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Palindromic Partitioning.cpp diff --git a/Palindromic Partitioning.cpp b/Palindromic Partitioning.cpp new file mode 100644 index 0000000..de61f55 --- /dev/null +++ b/Palindromic Partitioning.cpp @@ -0,0 +1,33 @@ +// User function Template for C++ + +class Solution{ +public: + bool isPalindrome(int i, int j, string& str) { + while(i&dp) { + if(i==n) { + return 0; + } + int mini = INT_MAX; + if(dp[i]!=-1) return dp[i]; + + for(int j = i; jdp(n,-1); + return solve(0,n,str,dp)-1; + } +};