id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\n vector<vector<string>> res;\n string str;\nbool isPalindrome(string s) {\n\n if (s == \"\")\n return false;\n\n if(s.size() == 1)\n return true;\n\n for (int i = 0; i < s.size() / 2; ++i) {\n if (s[i] != s[s.size() - i - 1])\n return false;\...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> ans;\n\n bool check(vector<string>v){\n for(int i=0; i<v.size(); i++){\n string temp = v[i];\n string revtemp = temp;\n reverse(temp.begin(), temp.end());\n if(temp != revtemp){return false;}\n ...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> result;\n bool isPalin(vector<string> vec){\n for(string s:vec){\n for(int i=0;i<s.size()/2;i++){\n if(s[i]!=s[s.size()-1-i]){\n return false;\n }\n }\n }\n r...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n\n bool isPalindrome(string s)\n {\n for(int i=0; i<s.length()/2; i++)\n if(s[i]!=s[s.length()-1-i])\n return false;\n return true;\n }\n\n set<vector<string>> partition_reverse(string s) \n {\n if(s.length()==1)\n ...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n\n\nbool pal(string str)\n{\n int n=str.length();\n for(int i=0;i<n/2;i++)\n {\n if(str[i]!=str[n-i-1]) \n {\n return false;\n }\n }\nreturn true;\n}\n\nvoid solve(vector<vector<string>>&ans,string str,int i,vector<string>v)\n{ \nif(i...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> partition(string s) {\n int n = s.length();\n vector<vector<bool>> palindromes(n, vector<bool>(n, false));\n for (int end = 0; end < n; end++) {\n for (int start = 0; start <= end; start++) {\n if (s[start]...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": ";\nclass Solution {\npublic:\n bool isPalindrome(int i, int k, string& s) {\n while (i <= k) {\n if (s[i] != s[k]) {\n return false;\n }\n i++;\n k--;\n }\n return true;\n }\n // Brute force: Cut or not cut an every si...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> partition(string s) {\n vector<vector<string>> result;\n backtrack(result, s, {\"\"}, 0);\n return result;\n }\n bool isPal(string s){\n int i = 0;\n int j = s.size()-1;\n while(i <= j){\n if(s[...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> partition(string s) {\n vector<vector<string>> result;\n backtrack(result, s, {\"\"}, 0);\n return result;\n }\n bool isPal(string s){\n int i = 0;\n int j = s.size()-1;\n while(i <= j){\n if(s[...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> partition(string s) {\n vector<string> pf;\n vector<vector<string>> ans;\n ans = solve(s, pf);\n return ans;\n }\n\n unordered_map<string, bool> pals;\n bool isPalindrome(string s) {\n if (s.length() == 1) {\n...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> partition(string s) {\n vector<string> pf;\n vector<vector<string>> ans;\n ans = solve(s, pf);\n return ans;\n }\n\n unordered_map<string, bool> pals;\n bool isPalindrome(string s) {\n if (s.length() == 1) {\n...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "using palindromes = std::vector<std::vector<std::string>>;\nusing st = std::vector<std::string>;\n\nclass Solution {\nprivate:\n palindromes ans;\n bool isPalindrome(std::string s)\n {\n bool res = true;\n int n = s.length();\n for (int i = 0; i < n / 2; i++)\n if (s[...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "using palindromes = std::vector<std::vector<std::string>>;\nusing st = std::vector<std::string>;\n\nclass Solution {\nprivate:\n palindromes ans;\n bool isPalindrome(std::string s)\n {\n bool res = true;\n int n = s.length();\n for (int i = 0; i < n / 2; i++)\n if (s[...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> pal_parts;\n vector<vector<int>> dp;\n bool is_palindrome(string s, int i, int j){\n if(i == j) dp[i][j] = 1;\n else if(i + 1 == j){\n dp[i][j] = 0;\n if(s[i] == s[j]) dp[i][j] = 1;\n }\n else if(d...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>>ans;\n string temp;int n;\n bool is_palindrome(string s){\n int n=(int)s.size();\n int i=0;\n int j=n-1;\n while(j>=i){\n if(s[i]==s[j]){\n i++;--j;\n }\n else return 0;\n ...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n string s;\n int n;\n vector<vector<string>> ans;\n bool isPalindrome(int l,int r){\n while(l<r){\n if(s[l]!=s[r]) return 0;\n l++;\n r--;\n }\n return 1;\n }\n void rec(int x, vector<string> v){\n if(...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "/*\n * @lc app=leetcode id=131 lang=cpp\n *\n * [131] Palindrome Partitioning\n */\n\n// @lc code=start\nclass Solution\n{\npublic:\n vector<vector<string>> ans;\n bool check(string &xd)\n {\n int start = 0, end = xd.size() - 1;\n while (start <= end)\n {\n if (xd[s...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n\n vector<vector<string> >ans;\n bool isPalindrome(const std::string& s) {\n // Create a reversed copy of the string\n std::string reversed = s;\n std::reverse(reversed.begin(), reversed.end());\n\n // Compare the original string with the reversed string\n re...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\n void ans(string &s,int i,string str,vector<vector<string>> & res,vector<string> v)\n {\n string st=str;\n reverse(st.begin(),st.end());\n if(i==s.size())\n {\n if(str==st)\n {\n v.push_back(str);\n res.push_back(v);\n }\n ret...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n\n bool is_pal(string s){\n if(s.size() < 2) return true;\n\n for(int i = 0, j = s.size() - 1; i < j; i++, j--){\n if(s[i] != s[j]) return false;\n } \n return true;\n }\n\n void solve(string str, vector<vector<string>>& res, vector...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n bool is_palindrome(string &s, int st, int en) {\n while(st <= en) {\n if(s[st] != s[en]) {\n return 0;\n }\n st++;\n en--;\n }\n\n return 1;\n }\n void solve(string &s, int prev, int i, vect...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n bool check(vector<string>& temp) {\n for (auto str : temp) {\n int sz = str.size();\n for (int i = 0; i < sz / 2; i++) {\n if (str[i] != str[sz - 1 - i])\n return false;\n }\n }\n return t...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n bool check(vector<string>& temp) {\n for (auto str : temp) {\n int sz = str.size();\n for (int i = 0; i < sz / 2; i++) {\n if (str[i] != str[sz - 1 - i])\n return false;\n }\n }\n return t...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n bool check(string s){\n if(s.size()==0)return false;\n stack<char> st;\n for(auto ch:s)st.push(ch);\n int i=0;\n while(!st.empty() && i<s.size()){\n if(st.top()!=s[i])return false;\n st.pop();\n i++;\n ...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> partition(string s) {\n int n=s.size();\n vector<vector<bool>> t(n,vector<bool>(n,false));\n vector<vector<string>> result;\n vector <string> path;\n \n for(int i=0;i<n;i++)\n t[i][i]=true;\n \...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n void solve(int n, string s, int id, vector<string> &res, vector<vector<string>> &ans, vector<vector<bool>> dp){\n if(id==n){\n ans.push_back(res);\n }\n for(int i=id; i<n; i++){\n string just = s.substr(id, i-id+1);\n if(d...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> results;\n\n vector<vector<string>> partition(const string &s) {\n vector<string> base;\n\n for (char i: s) {\n base.push_back(string(1, i));\n }\n\n recursion(base, {});\n return results;\n }\n\n v...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>>ans;\n int n;\n bool check(int i,int j,string &s){\n while(i<=j){\n if(s[i]!=s[j]){\n return false;\n }\n i++;\n j--;\n }\n return true;\n }\n void func(int index,int last,vecto...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(string s) {\n int n = s.size();\n for (int i = 0; i <= n / 2; i++) {\n if (s[i] != s[n - 1 - i]) {\n return 0;\n }\n }\n return 1;\n }\n\n vector<vector<string>> partition(string s) {\n ...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> partition(string s) {\n // find all palindromes first (?) and their start and ends\n vector<vector<bool>> isP(s.size(), vector<bool>(s.size(), false));\n for (int i = 0; i < s.size(); i++) {\n isP[i][i] = true;\n }...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> partition(string s) {\n // find all palindromes first (?) and their start and ends\n vector<vector<bool>> isP(s.size(), vector<bool>(s.size(), false));\n for (int i = 0; i < s.size(); i++) {\n isP[i][i] = true;\n }...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n\nunordered_map<string,vector<vector<string>>> cache;\n\nbool isPalindrome(string s)\n{\n int i = 0, j = s.length()-1;\n while(i<j)\n {\n if(s[i]!=s[j]) return false;\n i++;\n j--;\n }\n return true;\n}\n\nvector<vector<string>> proc(string s)\...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> partition(string s) {\n unordered_map<string, vector<vector<string>>> memo;\n dfs(s, memo);\n return memo[s];\n }\n\n vector<vector<string>> dfs(string s, unordered_map<string, vector<vector<string>>>& memo)\n {\n if...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n\n bool pal(string s, int st, int en){\n for (int i = st; i < en+1; i++) if (s[i] != s[st + en - i]) return false;\n return true;\n }\n\n vector<vector<string>> comb(vector<string>& k, string s, int st){\n vector<vector<string>> ans;\n if (st ...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n\n bool pal(string s, int st, int en){\n for (int i = st; i < (en+1+st)/2; i++) if (s[i] != s[st + en - i]) return false;\n return true;\n }\n\n vector<vector<string>> comb(vector<string>& k, string s, int st){\n vector<vector<string>> ans;\n ...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> ans;\n bool palindrom[20][20];\n string sub[20][20];\n bool cekPalin(string s){\n int len = (s.size()/2);\n int len2 = s.size();\n bool palin=true;\n for(int i=0;i<len;i++){\n if(s[i]!= s[len2-i-1]){\n ...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\n private:\n bool ispalindrome(string str,int s,int e){\n while(s<e){\n if(str[s]!=str[e]){return false;}\n s++;\n e--;\n }\n return true;\n}\n\nvoid fn(string &str, int n, vector<vector<string>>&ans,vector<pair<int,int>>temp,int s=0,int e =0){\n boo...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>>v;\n void T(vector<string>&temp,int i, string s,\n vector<vector<bool>>dp, int n ){\n if (i>=n){\n v.push_back(temp);\n return;\n }\n for (int ind = i; ind<n; ind++){\n if (dp[i][ind]){\n ...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\nstring s;\nint dp[18][18];\nvector<vector<string>> dp1[18][18];\nvector<vector<string>> pp;\n vector<vector<string>> get(int i, int j) {\n if(i>j) return {{}};\n if(i==j) return {{s.substr(i,j-i+1)}};\n if(dp1[i][j] != pp) return dp1[i][j];\n vector...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n string partS(string s, int start, int end) {\n string result = \"\";\n string rev = \"\";\n\n // Extract substring from 'start' to 'end-1'\n for (int i = start; i < end; i++) {\n result += s[i];\n }\n\n // Reverse the subst...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "\nclass Solution {\npublic:\nbool check(string s){\n int n=s.size();\n for(int i=0;i<n/2;i++){\n if(s[i]!=s[n-1-i]){\n return false;\n }\n }\n return true;\n}\nvoid solve(vector<vector<string>>&v,int i,vector<string>s,string str,string arr){\n int n=arr.size();\n// ...
131
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p> <p>&nbsp;</p> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<string>> ans;\n void fun(string s,int i,int prev,vector<string> res){\n if(i==s.size()){\n res.push_back(s.substr(prev,i-prev));\n bool checker=true;\n for(int k=0;k<res.size();k++){\n int l=0;\n int r=res[k].size...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
0
{ "code": "class Solution {\npublic:\n bool isPalindrome(int i, int j, string &s){\n while(i<j){\n if(s[i] != s[j]) return false;\n i++;\n j--;\n }\n return true;\n }\n int f(int i, int n, string &s, int dp[]){\n if(i==n) return 0;\n if(dp[i...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
0
{ "code": "class Solution {\npublic:\n bool isPalindrome(string s, int start, int end){\n while(start<end){\n if(s[start++] != s[end--])\n return false;\n }\n return true;\n }\n\n int helper(string &s, int i, int n, vector<int> &dp){\n if(i == n)\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n typedef long long ll;\n vector <ll> manacher(string &s)\n {\n s = '#' + s + '#';\n ll n = s.size();\n vector <ll> p(n , 1); \n ll l = 1, r = 1;\n for (ll i = 1; i < n; i++)\n {\n if(l+r-i>=0)\n p[i] = max(0...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\n\npublic:\n\n bool isPalindrome(string& s, int start, int end)\n {\n while (start <= end)\n {\n if (s[start++] != s[end--]) return false;\n }\n return true;\n }\n\n int minCut(string s)\n {\n int n = s.size();\n queue<pai...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n int n = s.size();\n vector<int>dp(n + 1, INT_MAX);\n dp[0]=0;\n vector<bool>prevp(n, 0), curp(n, 0);\n prevp[0] = 1;\n curp[0] = 1;\n for(int i=1;i<=n;i++){\n for(int j=0;j<i;j++){\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n std::unordered_map<int, int> memo;\n return minCutRecursive(s, 0, memo) - 1;\n }\n\n int minCutRecursive(std::string& s, int start_index, std::unordered_map<int, int>& memo)\n {\n if (start_index == s.length())\n {...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n bool ispalan(string &s,int i,int j){\n while(i<j){\n if(s[i]!=s[j])\n return false;\n i++;\n j--;\n }\n return true;\n }\n int f(string &s,int i,int n,vector<int>&dp){\n if(i==n){\n r...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n bool isPalindrome(string& s,int i,int j){\n if(s.length()==1){\n return true;\n }\n while(i<=j){\n if(s[i]!=s[j]){\n return false;\n }\n i++;\n j--;\n }\n return true;\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\n public:\n int minCut(string s) {\n const int n = s.length();\n // isPalindrome[i][j] := true if s[i..j] is a palindrome\n vector<vector<bool>> isPalindrome(n, vector<bool>(n, true));\n // dp[i] := the minimum cuts needed for a palindrome partitioning of s[0..i]\n vector<i...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\n public:\n int minCut(string s) {\n const int n = s.length();\n vector<vector<bool>> isPalindrome(n, vector<bool>(n, true));\n vector<int> dp(n, n);\n\n for (int l = 2; l <= n; ++l)\n for (int i = 0, j = l - 1; j < n; ++i, ++j)\n isPalindrome[i][j] = s[i] == s[j] ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n int solve(string &s, vector<int> &dp, int i, vector<vector<bool>> &palin){\n int n = s.size();\n int j = n-1;\n if(i>=j) return 0;\n\n if(dp[i]!=-1){\n return dp[i];\n }\n\n if(palin[i][n-1]) return dp[i]=0;\n\n int ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n vector<vector<bool>> p_hai;\n int n;\n vector<int> dp;\n int solve(int prev,string& s){\n if(prev==n-1){\n return 0;\n }\n if(dp[prev]!=-1){\n return dp[prev];\n }\n\n int ans=1e9;\n for(int i=prev;i<n;i...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n int dp[2005];\n \n vector<vector<bool>> is_palin;\n \n \n void fill_palin(string str)\n {\n int n = str.size();\n \n for(int gap = 0; gap < n; gap++)\n {\n for(int i = 0; i + gap < n; i++)\n {\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n int dp[2005];\n \n vector<vector<bool>> is_palin;\n \n \n void fill_palin(string str)\n {\n int n = str.size();\n \n for(int gap = 0; gap < n; gap++)\n {\n for(int i = 0; i + gap < n; i++)\n {\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\n int n;\n string s;\n vector<int> dp;\n vector<vector<bool>> done, pal;\n bool isPal(int l,int r){\n if(l>=r) return true;\n if(done[l][r]) return pal[l][r];\n done[l][r]=true;\n return pal[l][r] = (s[l]==s[r]) ? isPal(l+1,r-1) : false;\n }\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\n\n\tbool dp[2005][2005];\n\tbool vis[2005][2005];\n\tint n;\n\n\tbool isPal(int i, int j, string &s) {\n\t\tif (i >= j) {\n\t\t\treturn true;\n\t\t}\n\t\tif (vis[i][j]) {\n\t\t\treturn dp[i][j];\n\t\t}\n\t\tvis[i][j] = 1;\n\t\tif (s[i] != s[j]) {\n\t\t\treturn dp[i][j] = 0;\n\t\t}\n\t\tre...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\n public:\n std::array<std::vector<int>, 26> locations{};\n std::array<bool, 2000> seen{false};\n\n constexpr Solution() {\n for (auto& vec : locations) {\n vec.reserve(2000);\n }\n }\n\n constexpr static auto check(const std::string& s, int l, int r) -> bool {\n while (...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "\n\nint static t[2002][2002];\nclass Solution {\n \npublic:\n bool ispalindrome(string &s, int i,int j){\n if(i>=j){\n return true;\n }\n while(i<j){\n if(s[i]!=s[j]){\n return false;\n }\n i++;\n j--;\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "int dp1[2005][2005];\nint dp2[2005];\n\nint check(int l, int r, string &s)\n{\n if(l>=r)\n return dp1[l][r]=1;\n\n if(dp1[l][r]!=-1)\n return dp1[l][r];\n\n if(s[l]==s[r])\n return dp1[l][r]=check(l+1,r-1,s);\n else\n return dp1[l][r]=0;\n}\n\nint solve(int i, string &s)\n{\n int...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n int n = s.length();\n int dp[n][n];\n for (int diff = 0; diff < n; diff++) {\n for (int i = 0, j = diff; j < n; j++, i++) {\n if (diff == 0) {\n dp[i][j] = 1;\n } else if...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n // int dp[2002], p[2002][2002];\n // int n;\n // int func(string &s, int i){\n \n // }\n\n int minCut(string s) {\n int n = s.size();\n int dp[n][n];\n memset(dp, 0, sizeof(dp));\n for (int i=0; i<n; i++) dp[i][i] = 1;\n f...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n int n = s.size();\n int dp[n][n];\n for(int i=0;i<n;i++) dp[i][i]=1;\n for(int i=1;i<n;i++){\n dp[0][i]=1+dp[0][i-1];\n for(int j=i-1;j>0;j--){\n if(s[j]==s[i]){\n if(i==j+1...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
2
{ "code": "class Solution {\npublic:\n string s;\n int n;\n int pal[2001][2001];\n int dp[2001];\n int pali(int l,int r)\n {\n if(l>=r)\n {\n return 1;\n }\n if(pal[l][r]!=-1)\n {\n return pal[l][r];\n }\n if(s[l]==s[r])\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "auto speedUp = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n int minCut(string &s) {\n int n = s.size();\n int memo[n][n];\n memset(memo, -1, sizeof(memo));\n for(int i = 0; i <...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n int n=s.size();\n int memo[2000][2000]={0};\n if(n<2){\n return 0;\n }\n\n vector<int> dp(n+1,n);\n //build the valid Palindrome map\n for(int i=0; i<n; i++){\n int j;\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n\n bool isPal(string &s) {\n int i=0, j= s.size()-1;\n while(i<=j && s[i]==s[j]) {\n i++;\n j--;\n } \n return (i>j);\n }\n\n\n int minCut(string s) {\n int n = s.size();\n vector<int> dp(n,n);\n\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\nbool palindrome[2001][2001];\nint t[2001][2001];\nvoid fillPalindrome(string &s) {\n int n = s.length();\n for (int i = 0; i < n; i++) {\n palindrome[i][i] = true;\n }\n for (int i = 0; i < n - 1; i++) {\n palindrome[i][i + 1] = (s[i] == s...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int t[2001][2001];\n bool pal[2001][2001]; // Precomputed palindrome table\n\n void precomputePalindromes(string &s) {\n int n = s.size();\n for (int i = 0; i < n; i++) {\n pal[i][i] = true; // Single character is always a palindrome\n }...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int t[2001][2001];\n bool palindromeTable[2001][2001];\n \n // Preprocess to check if substring s[i..j] is a palindrome\n void preprocessPalindrome(string &s) {\n int n = s.size();\n for (int i = 0; i < n; ++i) {\n palindromeTable[i][i] = ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "#define pb push_back\n#define mp make_pair\n#define fi first\n#define se second\n#define ins insert\n#define vii vector<int>\n#define pii pair<int,int>\nconst int N = 2001;\nvii dp(N,-1);\nint n;\n\nvoid initialize(){\n for(int i=0;i<=n;i++)\n dp[i] = -1;\n}\n\nbool isPalindrome(int startIndex,st...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(string& s){\n int i=0;\n int j=s.size()-1;\n while(i<j){\n if(s[i]!=s[j]) return false;\n i++;\n j--;\n }\n return true;\n }\n // int f(int i,string s,vector<int>& dp){\n // if(...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "/*\nitself is palindrome, easy\n\nwe must find some t such that [0,t] is, and deal with the rest, and we want to maximise t (recur);\nnaive: from end call check palindrom one by one (probably not that bad, O(n^2))\n\nreuseable sub_structure? \n[0,t] => [1,t-1] not very useful\n\nmemorised dp?\n\n*/\nclass ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(string &s) {\n int i = 0;\n int j = s.size() - 1;\n while (i < j) {\n if (s[i] != s[j])\n return false;\n i++;\n j--;\n }\n return true;\n }\n int solve(int i, string& s...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool palindrome(string &s)\n {\n int n=s.length();\n // bool flag=true;\n for(int i=0; i<n/2; i++)\n {\n if(s[i]!=s[n-i-1])\n return false;\n }\n return true;\n }\n int f(int i, string &s, vector<int> &d...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool check(string &s){\n int i=0;\n int j=s.size()-1;\n while(i<j){\n if(s[i]!=s[j]){\n return false;\n }\n i++;\n j--;\n\n\n }\n return true;\n }\n int n;\n int recurssion(...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool isPallin(string st) {\n for (int i = 0; i <= st.size() / 2; ++i) {\n if (st[i] != st[st.size() - i - 1])\n return false;\n }\n return true;\n }\n // int func(int ind, string s, int n, vector<int>& dp) {\n // if ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "// class Solution {\n// public:\n// int dp[2001][2001];\n// // bool isPalin(string s ,int i ,int j){\n// // if(i>=j){\n// // return true;\n// // }\n// // if(s[i]!=s[j]){\n// // return false;\n// // }\n// // return isPalin(s,i+1,j-1);\n...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n // vector<vector<int>> memoCuts; // i,j = min cuts for substring starting from i and ending at j\n vector<int> memoCuts;\n vector<vector<optional<bool>>> memoPalindrome; // i, j = if i-j is a palindrome\npublic:\n int minCut(string s) \n {\n // memoCuts = vector<vec...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n // vector<vector<int>> memoCuts; // i,j = min cuts for substring starting from i and ending at j\n vector<int> memoCuts;\n vector<vector<optional<bool>>> memoPalindrome; // i, j = if i-j is a palindrome\npublic:\n int minCut(string s) \n {\n // memoCuts = vector<vec...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n vector<vector<optional<bool>>> palindromeMemo;\n vector<int> minCuts;\n\n int n;\npublic:\n int minCut(string s) \n {\n n = s.size();\n\n palindromeMemo.resize(n, vector<optional<bool>>(n, std::nullopt));\n minCuts = vector(s.size(), -1);\n\n re...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n vector<int> cutsDp;\n cutsDp.resize(s.length());\n for (int i = 1; i < s.length(); i++) {\n cutsDp[i] = i;\n }\n for (int mid = 0; mid < s.length(); mid++) {\n // check for odd length palindrome...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n vector<int> cutsDp;\n cutsDp.resize(s.length());\n for (int i = 1; i < s.length(); i++) {\n cutsDp[i] = i;\n }\n for (int mid = 0; mid < s.length(); mid++) {\n // check for odd length palindrome...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n// #include <iostream>\n// #include <vector>\n// #include <deque>\n// #include <string>\n// #include <algorithm>\n// #include <limits>\n\n// using namespace std;\n\npublic:\n int func(const string& word) {\n int n = word.length();\n vector<int> dp(n + 1, -1);\n int...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "int dp[2002][2002];\nint dp2[2002][2002];\nclass Solution {\npublic:\n bool check(int l, int r, string &s)\n {\n if(l==r)return true;\n if(r-l==1)return s[l]==s[r];\n if(dp[l][r]!=-1)return dp[l][r];\n return dp[l][r]=(s[l]==s[r])&&check(l+1,r-1,s);\n }\n int cuts(in...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n unordered_map<string,int>mp;\n bool is(string &s) {\n int i=0;\n int j=s.size()-1;\n while (i <= j) {\n if (s[i] != s[j])\n return false;\n i++;\n j--;\n }\n mp[s]=1;\n return true;\n }\n\n...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n\n\npublic:\n int minCut(string s) {\n int n = (int)s.size();\n\n int dp[n][n];\n int isPal[n][n];\n for (int i = 0; i < n; ++i) {\n isPal[i][i] = 1;\n dp[i][i] = 0;\n }\n\n for (int i = n - 1; i >= 0; --i) {\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n int rec(string S, int st, int end, vector<vector<int>>& dp,\n vector<vector<int>> isPal) {\n if (isPal[st][end])\n return 0;\n else {\n if (dp[st][end] != -1)\n return dp[st][end];\n int ans = INT_MAX;\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n int rec(string S, int st, int end, vector<vector<int>>& dp,\n vector<vector<int>> isPal) {\n if (isPal[st][end])\n return 0;\n else {\n if (dp[st][end] != -1)\n return dp[st][end];\n int ans = INT_MAX;\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int dp[2001][2001];\n int palindrome[2001][2001];\n int isPalindrome(string& s,int l,int r)\n {\n if(l >= r)\n {return palindrome[l][r] = 1;}\n if(palindrome[l][r] != -1)\n {\n return palindrome[l][r];\n }\n while(...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n int minCut(string s) {\n ll n=s.size();\n ll pal[n][n],dp[n+1];\n memset(pal,0,sizeof(pal));\n memset(dp,0x3f,sizeof(dp));\n\n for(ll i=0;i<n;i++)\n for(ll j=0;j<n;j++)\n pal[i][j]=(j<=i);\n\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n unordered_map<int,int>dp;\n unordered_map<int,vector<int>>tap;\n int recur(string &s,int i){\n if(s.length()==i+1)return dp[i]=0;\n if(dp.count(i))return dp[i];\n int result=INT_MAX;int n = s.length();\n for(int j =0;j<tap[i].size();j++){\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int dp[2005][2005];\n\n int is_palindrome(string& s) {\n if (s.size() == 1)\n return 1;\n\n int n = s.size();\n int x = (n + 1) / 2;\n int j = n - 1;\n for (int i = 0; i <= x; i++, j--) {\n if (i > j)\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n string st;\n int n;\n int dp[2001];\n int isTrue[2003][2003];\n\n void isPalin(){\n for(int i = 0; i<n; ++i){\n isTrue[i][i] = 1;\n }\n\n for(int i = 0; i<n-1; ++i){\n if(st[i] == st[i+1]){\n isTrue[i][i+1]...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n public: int bfs(int node, vector<vector<int>>count, int curr = 0) {\n int n = count.size();\n if (node == n) return curr;\n int k = INT_MAX;\n for (auto x: count[node]) {\n k = min(k, bfs(x+1, count, curr+1));\n }\n k = min(bfs(nod...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n int n = s.size();\n vector<vector<bool>> dp(n, vector<bool>(n, false));\n vector<vector<int>> next(n + 1, vector<int>(0));\n\n for (int delta = -1; delta <= n; delta++){\n for (int i = 0; i < n; i++){\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool isPali(string& s, int i, int j) {\n while (i < j) {\n if (s[i] != s[j]) return false;\n i++;\n j--;\n }\n return true;\n }\n\n int minCut(string s) {\n\n priority_queue<pair<int,int>, vector<pair<int,int>...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n\n vector<vector<int> > palinLen;\n\n void palindromeCount(const string& s, int left, int right) {\n while (left >= 0 && right < s.length() && s[left] == s[right]) {\n palinLen[left].push_back(right);\n --left;\n ++right;\n }\n...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "int pdp[2004][2004];\nint dp[2004];\nclass Solution {\npublic:\n int func(int idx, vector<int>adj[], int n)\n {\n if(idx==n)\n return 0;\n if(dp[idx]!=-1)\n return dp[idx];\n int res=1e9;\n for(auto &x: adj[idx])\n {\n res=min(res, 1+func(x+...