id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\npublic:\n int n;\n string s1, s2;\n bool memo[32][32][32];\n bool vis[32][32][32];\n bool dp(int l, int i, int j)\n {\n //cout << l << \" \" << i << \" \" << j << \"\\n\";\n if (l == 1)\n {\n //cout << i << \" \" << j << \" \" << (s1[i] ==...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\npublic:\n bool isScramble(string s1, string s2) {\n int n=s1.size(); if (n!=s2.size()) return 0;\n\n bool dp[1+n][n][n];\n\n for (int l=0; l<1+n; l++) for (int i=0; i<n; i++) for (int j=0; j<n; j++) dp[l][i][j]=0;\n for (int i=0; i<n; i++)\n for (...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\npublic:\n int dp[51][51][51];\n string s, t;\n\n bool rec(int l, int r, int i) {\n int j=r-l+i;\n // base case\n if (l==r) return s[l]==t[i];\n\n if (dp[l][r][i]!=-1) return dp[l][r][i];\n\n bool flag=0;\n for (int k=1; k<=(r-l); k++) {\n...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\npublic:\n int dp[51][51][51];\n string s, t;\n\n bool rec(int l, int r, int i) {\n int j=r-l+i;\n // base case\n if (l==r) return s[l]==t[i];\n\n if (dp[l][r][i]!=-1) return dp[l][r][i];\n\n bool flag=0;\n for(int k=1; k<(r-l+1); k++){\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\npublic:\n bool isScramble(string s1, string s2) {\n int n = s1.size();\n int f[n][n][n + 1];\n memset(f, -1, sizeof(f));\n function<bool(int, int, int)> dfs = [&](int i, int j, int k) -> int {\n if (f[i][j][k] != -1) {\n return f[i]...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\npublic:\n bool isScramble(string s1, string s2) {\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n int n = s1.size();\n if (n != s2.size()) return false;\n if (s1 == s2) return true;\n\n // dp[i][j][len] -> is s1[i:i+l...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\n // Problem says max length == 30\n unsigned char dp[31][31][31];\n std::string s1, s2;\n\npublic:\n bool inner(int s1idx, int s2idx, int size) {\n unsigned char &entry = dp[size-1][s1idx][s2idx];\n if(entry != 0xFF) {\n return entry == 1;\n }\n\n if(memcmp(&s1[s1idx]...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\n // Problem says max length == 30\n unsigned char dp[31][31][31];\n std::string s1, s2;\n\npublic:\n bool inner(int s1idx, int s2idx, int size) {\n unsigned char &entry = dp[size-1][s1idx][s2idx];\n if(entry != 0xFF) {\n return entry == 1;\n }\n\n if(memcmp(&s1[s1idx]...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\n using BT = std::vector<unsigned char>;\n\n bool solve(const int N,\n const std::vector<std::array<int,26>>& origPSA,\n const std::vector<std::array<int,26>>& scraPSA, \n BT& dp,\n const int oStart, const int oEnd, const int sStart, const int sEnd,const ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "int dp[30][30][30][30];\n\nbool f(string& s1,string& s2,int l1,int r1,int l2,int r2)\n{\n if (l1==r1) return (s1[l1]==s2[l2]);\n if (dp[l1][r1][l2][r2]!=-1) return dp[l1][r1][l2][r2];\n bool ok=false;\n for (int i=l1;i<r1;i++){\n int d=i-l1+1;\n ok|=(f(s1,s2,l1,i,l2,l2+d-1) && f(s...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "int dp[31][31][31][31];\nclass Solution {\npublic:\n bool rec(int si,int sj,int ti,int tj,string &s,string &t)\n {\n if(ti==tj)\n {\n if(s[si]==t[ti])return true;\n return false;\n }\n if(dp[si][sj][ti][tj]!=-1)return dp[si][sj][ti][tj];\n int ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\npublic:\n bool isScramble(string s1, string s2) {\n vector<vector<bitset<30>>> tbl(30, vector<bitset<30>>(30, 0));\n int l = s1.length();\n int i, j, p, q, t;\n for (i = 0; i < l; i++)\n for (j = 0; j < l; j++) {\n if (s1[i] == s2[j...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\n private:\n int dp[31][31][31];\n bool solve(string &s1, string &s2, int l1, int l2, int len) {\n if (len == 0) return dp[l1][l2][len] = true;\n if (dp[l1][l2][len] != -1) return dp[l1][l2][len];\n if (s1.substr(l1, len) == s2.substr(l2, len)) return dp[l1][l2][len] = true;\n\n...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\n private:\n int dp[32][32][32];\n bool solve(string &s1, string &s2, int l1, int l2, int len) {\n if (len == 0) return dp[l1][l2][len] = true;\n if (dp[l1][l2][len] != -1) return dp[l1][l2][len];\n if (s1.substr(l1, len) == s2.substr(l2, len)) return dp[l1][l2][len] = true;\n\n...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\n vector<vector<vector<short>>> dp;\n bool helper(string& s1, string& s2, int l, int r, int i) {\n if (l == r) {\n return s1[l] == s2[i];\n }\n if (dp[l][r][i] == -1) {\n dp[l][r][i] = 0;\n for (int j = 0; j < r - l; j++)\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\n int dp[31][31][31];\n string s1,s2;\n bool allEqual(int l1,int r1,int l2,int r2){\n int len = r1-l1+1;\n for(int i=0;i<len;i++){\n if(s1[i+l1]!=s2[i+l2]) return false;\n }\n return true;\n }\npublic:\n bool isScramble(string s1, strin...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\npublic:\n bool isSameSet(string s1, string s2) {\n sort(s1.begin(), s1.end());\n sort(s2.begin(), s2.end());\n return s1 == s2;\n }\n \n bool isScrambleRec(string &s1, string &s2, int si1, int si2, int sl, unordered_map<unsigned int, bool> &m) {\n if...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\npublic:\n bool isSameSet(string& s1, string& s2) {\n sort(s1.begin(), s1.end());\n sort(s2.begin(), s2.end());\n return s1 == s2;\n }\n \n bool isScrambleRec(string &s1, string &s2, int si1, int si2, int sl, unordered_map<unsigned int, bool> &m) {\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\npublic:\n bool isScramble(string s1, string s2) {\n int n = s1.size();\n if (n != s2.size()) return false;\n if (s1 == s2) return true;\n\n // dp[i][j][len] -> is s1[i:i+len] a scrambled version of s2[j:j+len]\n vector<vector<vector<bool>>> dp(n, vect...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
0
{ "code": "class Solution {\npublic:\n std::map<std::pair<std::string_view, std::string_view>, bool> memo;\n\n bool isScrambleRec(std::string_view a, std::string_view b) {\n int str_len = a.length();\n\n if(str_len == 1) {\n return a == b;\n }\n\n if(auto it = memo.find(st...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\npublic:\n int dp[41][41][41];\nbool helper(int l1, int r1, int l2, string &s1, string &s2)\n{\n int r2 = l2 + (r1 - l1);\n if (l1 > r1 || l2 > r2)\n return false;\n if (l1 == r1)\n return (s1[l1] == s2[l2]);\n\n if (dp[l1][r1][l2] != -1)\n return bool(d...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\npublic:\n map<string, bool> dp;\n\n bool isScramble(string s1, string s2) {\n if (s1 == s2) {\n return true;\n }\n\n if (s1.length() != s2.length()) {\n return false;\n }\n\n // Check if the sorted versions of the strings matc...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\npublic:\n string tar;\n map<string,bool> mp;\n bool rec(string s,int i,int j){\n string ss=s+\" \"+to_string(i)+\" \"+to_string(j);\n // cout<<i<<\" \"<<j<<endl;\n if(i==j){\n // cout<<\"inside equal \"<<i<<\" \"<<j<<\" \"<<s<<endl;\n if...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\npublic:\n unordered_map<string,bool> mp;\n bool isScramble(string s1, string s2) {\n \n if(s1.length() != s2.length())\n return false;\n if(s1.length() == 1)\n return s1[0] == s2[0];\n if(s1==s2) \n return true;\n\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "#include <string>\n#include <unordered_map>\n#include <vector>\n\nclass Solution {\npublic:\n // Memoization table to store the results of subproblems\n std::unordered_map<std::string, bool> memo;\n\n // Function to check if s2 is a scrambled version of s1\n bool isScram...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "\nclass Solution {\npublic:\n unordered_map<string,bool> hash;\n bool isScramble(string s1, string s2) {\n if(s1.size()!=s2.size()){\n return false;\n }\n if(s1==s2){\n return true;\n }\n if(hash.find(s1+s2)!=hash.end()){\n return ha...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\npublic:\n int dp[31][31][31][31];\n\n bool solve(int a, int b, int c, int d, string &s1, string &s2) {\n \n if (s1.substr(a, b - a) == s2.substr(c, d - c)) return true;\n\n if (dp[a][b][c][d] != -1) return dp[a][b][c][d];\n\n int n = b - a;\n\n for (in...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\n map<string,int> dp;\npublic:\n bool isScramble(string s1, string s2) {\n return get(s1+s2);\n }\n\n bool get(string s){\n\n // cout << \"get for \" << s << endl;\n\n if(dp.find(s) != dp.end()){\n return dp[s];\n }\n\n if(s.size() ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\npublic:\n bool func(string s1, string s2, unordered_map<string, bool> &mem) {\n if (s1 == s2) return true;\n if (s1.size() != s2.size()) return false;\n if (s1.size() == 1) return s1 == s2;\n\n string key = s1 + \"_\" + s2;\n if (mem.find(key) != mem.end()) return mem[key]...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "string rev(string s){\n reverse(s.begin(),s.end());\n return s;\n}\n\nclass Solution {\npublic:\n bool isScramble(string s1, string s2) {\n int n=s1.size();\n vector<vector<vector<bool>>> dp(n,vector<vector<bool>>(n,vector<bool>(n+1,false)));\n \n for(int k=1;k<=n;k++){\...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\npublic:\nunordered_map<string,bool> mp;\nbool solve(string s1, string s2)\n{\n if(s1==s2)\n return mp[s1+s2] = true;\n string ss = s1+s2;\n if(mp.find(ss)!=mp.end())\n {\n return mp[ss];\n }\n vector<int> f1(26,0), f2(26,0);\n int n = s1.size();\n for...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "enum MemoizationResult\n{\n UNSET = 0,\n TRUE,\n FALSE\n};\n\nclass Solution\n{\n // length->s1_index->s2_index->isScrambled\n vector<vector<vector<MemoizationResult>>> mMemoization;\n const char *mS1Start = nullptr;\n const char *mS2Start = nullptr;\n\npublic:\n bool isLetterCountE...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\n bool solve(const string& s1, const string& s2, int i1, int i2, int length,vector<vector<vector<int>>>& dp) {\n if(dp[i1][i2][length] != -1){\n return dp[i1][i2][length];\n }\n \n if (s1.substr(i1, length) == s2.substr(i2, length)) {\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\n int count = 0;\n int helper(string s1, string s2, int i1, int j1, int i2, int j2, vector<vector<vector<int>>> &dp) {\n if(dp[i1][i2][j1-i1+1]!=-1)\n return dp[i1][i2][j1-i1+1];\n if (i1 == j1) {\n return dp[i1][i2][j1-i1+1] = (s1[i1] == s2[i2]);\...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\npublic:\n vector<vector<vector<int>>> dp;\n\n bool scramble(string& s, string& t, int i, int j, int len) {\n if (dp[i][j][len] != -1)\n return dp[i][j][len];\n\n if (s.substr(i, len) == t.substr(j, len))\n return dp[i][j][len] = true;\n\n v...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
1
{ "code": "class Solution {\npublic:\n bool isScramble(string s1, string s2) {\n if (s1 == s2) {\n return true;\n }\n int n = s1.length();\n if (n != s2.length()) {\n return false;\n }\n vector<int> count(26, 0);\n for (int i = 0; i < n; i++) {...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n\n bool solve(int idx1, int idx2, int len, const string &s1, const string &s2, vector<vector<vector<int>>>& dp) {\n if (s1.substr(idx1, len) == s2.substr(idx2 , len)) {\n return true;\n }\n if(len == 1){\n return false;\n }\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n bool solve(int i, int j, int len, string &s1, string &s2, vector<vector<vector<int>>> &dp) {\n if(s1.substr(i, len) == s2.substr(j, len)) return true; \n //compare substring of s1 starting at index i of length len with substring of s2\n // starting at...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\n bool solve(vector<vector<vector<int>>>& dp, string& s1, string& s2, int length, int i, int j)\n {\n if(length == 1)\n return s1[i] == s2[j];\n\n if(s1.substr(i, length) == s2.substr(j, length))\n return true;\n\n if(dp[length][i][j] != -1)...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\n bool solve(vector<vector<vector<int>>>& dp, string& s1, string& s2, int length, int i, int j)\n {\n if(length == 1)\n return s1[i] == s2[j];\n\n if(s1.substr(i, length) == s2.substr(j, length))\n return true;\n\n if(dp[length][i][j] != -1)...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> mp;\n\n bool solve(string& s1, string& s2, int i1, int i2, int len) {\n if (s1.substr(i1, len) == s2.substr(i2, len))\n return true;\n\n string key = to_string(i1) + \"_\" + to_string(i2) + \"_\" + to_string(len);\n\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n map<pair<string,string>,bool> dp;\n bool f(string s1,string s2){\n if(s1.size()!=s2.size()) return false;\n if(s1 == s2) return true;\n string t1=s1,t2=s2;\n sort(t1.begin(),t1.end());\n sort(t2.begin(),t2.end());\n if(t1!=t2) retu...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n bool solve(string s1, string s2, unordered_map<string, unordered_map<string, bool>> &dp) {\n if (s1 == s2) {\n return true;\n }\n \n if (dp[s1].find(s2) != dp[s1].end()) {\n return dp[s1][s2];\n }\n \n int...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\nprivate:\n string tgt;\n map<string, bool> dp;\n bool dfs(string &s, int l=0){\n string key = s + to_string(l);\n if(dp.find(key) != dp.end()) return dp[key];\n bool eq = 1;\n for(int i=0, j=l; i<s.size() and eq; i++, j++) eq = s[i] == tgt[j];\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\nunordered_map<string,bool> memo;\n bool solve(string s1, string s2){\n if (s1==s2){\n return true;\n }\n vector<int> freq1(26,0);\n for (int i=0;i<s1.size();i++) freq1[s1[i]-'a']++;\n vector<int> freq2(26,0);\n for (int i=...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\nunordered_map<string,bool>mp;\n \n bool solver(string s1,string s2){\n if(s1==s2){\n return true;\n }\n \n bool a=false;\n bool b=false;\n bool c=false;\n bool d=false;\n if(mp.find(s1+s2)!=mp.end()){\n re...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\n map<string, map<string, bool>> mp;\n int rec(string s1, string s2) {\n if (s1 == s2)\n return true;\n if (s1.size() != s2.size())\n return false;\n\n if (mp[s1].count(s2))\n return mp[s1][s2];\n \n int n = s1.s...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef unsigned long long ull;\ntypedef long long ll;\n\n\n\n\nclass Solution {\npublic:\n\nbool ismatch(string &s1 , int i ,int j , string &s2)\n{\n string s = s2.substr(i,j-i+1);\n if(s1 == s)\n {\n return true;\n }\n return false;\n}\...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n map <pair<string,string>,bool> mp;\n bool dp(string s1,string s2)\n {\n if (s1.size()!=s2.size()) return 0;\n if (s1 == s2) return 1;\n int n= s1.size();\n //base\n pair<string,string> key = {s1,s2};\n if (mp.count(key)) return mp[key];\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\nprivate:\n string tgt;\n map<string, bool> dp;\n bool dfs(string s, int l=0){\n string key = s + to_string(l);\n if(dp.find(key)!=dp.end()) return dp[key];\n string t = tgt.substr(l, s.size());\n // cout << \"Checking if \" << s << \" is a scramble of ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\n bool checkScrambleString(string str, string target, unordered_map<string, unordered_map<string, int>>& dp) {\n if (str == target) return true;\n if (str.length() == 1) return false;\n if (dp[str][target] != 0) {\n if (dp[str][target] == -1) return false...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n bool scramble(string s1,string s2,unordered_map<string,bool>&dp) {\n string key = s1 + \"#\" + s2;\n if(dp.find(key) != dp.end()) return dp[key];\n if(s1 == s2){\n return true;\n }\n int len = s1.size();\n vector<int> count...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> memo;\n bool isScramble(string s1, string s2) {\n if (s1 == s2) // Use == to compare strings instead of compare() function\n return true;\n if (s1.length() != s2.length()) // Check if lengths are different\n return false;\n if (s1...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\nmap<pair<string,string>,bool> mp;\nbool solve(string a,string b){\n if(a==b){\n return true;\n }\n if(a.size()<=1){\n return false;\n }\n if(mp.find({a,b})!=mp.end()){\n return mp[{a,b}];\n }\n int n=a.length();\n bool res=false;\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n map<pair<string, string>, bool> dp; \n\n bool solve(string s1 , string s2){\n int n = s1.length() ;\n\n if(s1 == s2){\n return true ;\n }\n if(n == 1){ \n return false ;\n }\n\n if(dp.find({s1 , s2}) != dp.end...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n map<pair<string, string>, bool> mpp;\n\n bool isScramble(string s1, string s2) {\n if (s1.size() != s2.size()) return false;\n if (s1 == s2) return true;\n\n if (mpp.find({s1, s2}) != mpp.end()) return mpp[{s1, s2}];\n\n int n = s1.size();\n for (int i = 1; i < ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n map<pair<string, string>, bool> mpp;\n\n bool isScramble(string s1, string s2) {\n if (s1.size() != s2.size()) return false;\n if (s1.size() == 0 || s2.size() == 0) return false;\n if (s1 == s2) return true;\n\n // Check if the result is already...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n bool isScramble(string s1, string s2) {\n map<string, bool> dp;\n if(s1 == s2) return true;\n return solve(s1, s2, dp);\n }\n\n bool solve(string s1, string s2, map<string, bool> &dp){\n int n = s1.length();\n if(n == 1){\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\n unordered_map<string, bool> dp;\npublic:\n bool isScramble(string s1, string s2) {\n if(s1 == s2) \n return true;\n\n if(s1.length() == 1)\n return false;\n\n string key = s1 + s2;\n if(dp.find(key) != dp.end())\n return ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n unordered_map<string,bool>mp;\n bool re(string s1, string s2){\n int n=s1.size();\n string t=s1+s2;\n if(mp.find(t)!=mp.end()){\n return mp[t];\n }\n if(s1==s2){\n return true;\n }if(s1.size()==1){\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n\n bool solve(string s1, string s2, unordered_map<string, bool>&dp)\n {\n if(s1 == s2)\n return true;\n\n string key = s1 + s2;\n\n if(dp.find(key) != dp.end())\n return dp[key];\n\n if(s1.length() != s2.length())\n {\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n int solve(vector<vector<vector<int>>>& dp,string s1, string s2, int i, int j, int len){\n if(len<=0){\n return 1;\n }\n if(s1.size()<i+len){\n return 0;\n }\n if(s2.size()<j+len){\n return 0;\n }\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "/*\n https://leetcode.com/problems/scramble-string/submissions/\n TC: O(N^2)\n*/\nclass Solution {\npublic:\n // checks if s2 is scrambled form of s1\n /*\n The idea is to find a position in string s1, from where scrambling must have\n started to create s2. So if k is the position...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"Ofast\", \"inline\", \"unroll-loops\", \"no-stack-protector\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native\", \"f16c\")\n#define ll long long\n#define deb(x) cout << #...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n map<string, bool>mp;\n bool solve(string s1, string s2)\n {\n if(s1 ==s2)\n return true;\n if(s1.length() <= 1)\n return false;\n string temp = s1+\"\"+s2;\n if(mp.find(temp) != mp.end())\n return mp[temp];\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n//for storing already solved problems\n unordered_map<string,bool> mp;\n \n \n bool isScramble(string s1, string s2) {\n //base cases\n \n int n = s1.size();\n \n //if both string are not equal in size\n if(s2.size()!=n)\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n//for storing already solved problems\n unordered_map<string,bool> mp;\n \n \n bool isScramble(string s1, string s2) {\n //base cases\n \n int n = s1.size();\n \n //if both string are not equal in size\n if(s2.size()!=n)\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n unordered_map<string,bool> mpp;\n bool isScramble(string s1, string s2) {\n //base case\n int n=s1.size();\n if(s1==s2) return true;\n if(n==1) return false;\n string key=s1+\" \"+s2;\n if(mpp.find(key)!=mpp.end()) return mpp[key];...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
2
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> dp;\n bool isScramble(string s1, string s2) {\n if(s1 == s2)\n return true;\n return scramble(s1, s2);\n }\n\n bool scramble(string s, string b) {\n if(s.size() != b.size())\n return false;\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic: \n bool solve(string s1,string s2,unordered_map<string,bool> &M){\n string key= s1+' '+s2;\n if(M.count(key)>0){\n return M[key];\n }\n else{\n M[key]=false;\n }\n if(s1 == s2) return M[key]=true;\n if(s1.si...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic: \n bool solve(string s1,string s2,unordered_map<string,bool> &M){\n string key= s1+' '+s2;\n if(M.count(key)>0){\n return M[key];\n }\n else{\n M[key]=false;\n }\n if(s1 == s2) return M[key]=true;\n if(s1.si...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> memo;\n bool isScramble(string s1, string s2) {\n int s1n = s1.length();\n if(s1n != s2.length()) return false;\n if(s1 == s2) return true;\n string key = s1 + \"|\" + s2;\n if (memo.find(key) != memo.end()) return memo[key];\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\nint dp[51][51][51][51];\n\n\nint sl(int l, int r, int l1, int r1, string& a, string& b, int n){ \n if(l==r){\n if(a[l]==b[l1]) return 1;\n return 0;\n }\n \n if(dp[l][r][l1][r1]!=-1) return dp[l][r][l1][r1];\n \n int ans=0;\n int d = l1-l;\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\nprivate:\n class Node {\n private:\n bool val;\n\n public:\n Node(bool val) {\n this->val = val;\n }\n bool getVal() {\n return this->val;\n }\n };\n\n \n\n bool scramble(string S, string T, unordered_map<s...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\nprivate:\n class Node {\n private:\n bool val;\n\n public:\n Node(bool val) {\n this->val = val;\n }\n bool getVal() {\n return this->val;\n }\n };\n\n\n\n bool scramble(string S, string T, unordered_map<strin...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> mp;\n string key(string a, string b)\n {\n return a + \"_\" + b;\n }\n bool isScramble(string s1, string s2) {\n if (s1.size() != s2.size())\n {\n return false;\n }\n if (s1 == s2)\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> map;\n\n bool isScramble(string s1, string s2) {\n if (s1.length() != s2.length()) return false;\n return f(s1, s2);\n }\n\n bool f(string s1, string s2) {\n if (s1 == s2) return true;\n if (s1.length() != s2.le...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\nprivate:\n unordered_map<string, bool>mp; \npublic:\n string f(string &s,int l,int d){\n int n = s.length();\n string ans = \"\";\n if(d==1){\n for(int i = 0 ; i<l ; i++)\n ans += string(1,s[i]);\n }\n else{\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n map<string,bool> m;\n bool isScramble(string x, string y) {\n if(x==y) return true;\n if(x.length()!=y.length()) return false;\n string z=x+\"_\"+y;\n if(m.find(z)!=m.end()) return m[z];\n for(int i=1;i<x.length();i++){\n string l=x.substr(0,i);\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n unordered_map<string, int> memo;\n bool solve(string a, string b){\n if(a.compare(b) == 0) return true;\n int n = a.length();\n if(n <= 1) return false;\n if(memo.find(a+b) != memo.end()) return memo[a+b];\n bool ans = false;\n for...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\n private:\n bool solve(string &s1,string &s2){\n if(s1==s2)return true;\n // if(s1.length()==1&&s1!=s2)return false;\n bool res=false;\n int n=s1.length();\n string key=s1+\"_\"+s2;\n if(mp.find(key)!=mp.end())return mp[key];\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "\nclass Solution {\n\nprivate:\n\n unordered_map<string,bool> dp;\n\n bool solve(string s1, string s2) {\n if(s1 == s2) return true;\n\n if(dp.find(s1 + s2) != dp.end()) return dp[s1 + s2];\n\n int n = s1.size();\n bool sub_check = false;\n\n for(int i=1;i<n;i++) {\...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n vector<vector<vector<char>>> memo;\n bool sameChars(vector<int>& c1, vector<int> c2) {\n for (int i = 0; i < 26; i++) {\n if (c1[i] != c2[i]) return false;\n }\n return true;\n }\n \n bool isOrder(string& s1, string& s2, int s1b, in...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n bool isScramble(string str1, string str2) {\n int n = str1.size(), m = str2.size();\n\n if(n != m){\n return false;\n }\n\n unordered_map<string, bool> dp;\n\n return solve(str1, str2, dp);\n }\n\n\n bool solve(string str1, ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n int func(unordered_map<string,int> &mp, string &s1, string &s2, int x1, int y1, int x2, int y2)\n {\n string sx1 = s1.substr(x1,y1-x1+1), sx2 = s2.substr(x2,y2-x2+1);\n\n string s= sx1;\n s.push_back(','); \n s += sx2;\n if(sx1==sx2)\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n map<string, bool> st_map;\n bool isScramble(string s1, string s2) {\n if(s1==s2)return true;\n if(s1.length()==1)return s1==s2;\n \n bool value = false;\n\n if(st_map.find(s1+\"*\"+s2)!=st_map.end()) return st_map[s1+\"*\"+s2];\n\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n unordered_map<string,bool>dp;\n bool isScramble(string s1, string s2) {\n if(s1.size()!=s2.size())return false;\n if(s1==s2)return true;\n if(s1.size()==1)return false;\n if(dp.find(s1+\"_\"+s2)!=dp.end())return dp[s1+\"_\"+s2];\n int n=s...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\nmap<string, bool>mp;\nbool f(string s1, string s2) {\n if (s1.size() == 1)return s1 == s2;\n if (mp.find(s1 + ' ' + s2) != mp.end())return mp[s1 + ' ' + s2];\n bool fl = 0;\n for (int i = 1; i < s1.size(); i++) {\n fl |= (f(s1.substr(0, i), s2.substr(0, i)) && ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n map<string,bool> mpp;\n \n bool isScramble(string s1, string s2) {\n if (s1 == s2) return true;\n \n \n if (mpp.find(s1 + \",\" + s2) != mpp.end()) return mpp[s1 + \",\" + s2];\n\n int n = s1.size();\n\n for (int i = 1; i < n; i...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\nmap<string, bool> mpp;\nbool solve(string A, string B, int n){\n if(A==B){\n return mpp[A+\"#\"+B]=true;\n }\n if(mpp.find(A+\"#\"+B)!=mpp.end()){\n return mpp[A+\"#\"+B];\n }\n if(A.size()==1){\n return false;\n }\n for(int i=1;i<n;i++){...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n\n bool solve(string s1,string s2,unordered_map<string,bool>&dp){\n if(s1==s2) return true;\n if(dp.find(s1+'*'+s2)!=dp.end()) return dp[s1+'*'+s2];\n int n = s1.size();\n for(int i=1;i<n;i++){\n if((solve(s1.substr(0,i),s2.substr(0,i),dp...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\n unordered_map<string,bool>m;\n bool helper(string s1,string s2){\n if(s1==s2){\n return 1;\n }\n\n if(m.count(s1+\"#\"+s2) > 0){\n return m[s1+\"#\"+s2];\n }\n\n int n=s1.length();\n\n for(int i=1;i<s1.length();i++){\n...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\n bool solve(string s1, string s2, unordered_map<string, bool>& mp)\n {\n if(s1 == s2)\n {\n return true;\n }\n if(s1.size() != s2.size())\n {\n return false;\n }\n \n string key = s1 + \"_\" + s2;\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> mp;\n bool solve(string s1 , string s2){\n if(s1 == s2) return true;\n if(s1.size() != s2.size()) return false;\n string key = s1 + \"_\" + s2;\n if(mp.find(key) != mp.end())\n return mp[key];\n\n bo...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n unordered_map<string,bool>mp;\n bool solve(string &s, string &t){\n int n = s.length();\n if(s==t)return true;\n if(n==1){\n return s[0]==t[0];\n }\n string temp = \"\";\n temp += s;\n temp.push_back('$');\n ...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\nprivate:\n map<pair<string, string>, bool> cache;\n\npublic:\n bool isScramble(string s1, string s2) {\n if(s1.size() != s2.size()) return false;\n if(s1.size() == 0) return true;\n if(s1.size() == 1) return s1[0] == s2[0];\n\n if(s1 > s2) swap(s1, s2);\n...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n bool isScramble(string s1, string s2) {\n map<pair<string, string>, bool> dp; \n auto dfs = [&](auto &self, string a, string b) -> bool\n {\n if(a == b)\n return 1; \n if(a.length() != b.length())\n retu...
87
<p>We can scramble a string s to get a string t using the following algorithm:</p> <ol> <li>If the length of the string is 1, stop.</li> <li>If the length of the string is &gt; 1, do the following: <ul> <li>Split the string into two non-empty substrings at a random index, i.e., if the string is <code>s</code>, di...
3
{ "code": "class Solution {\npublic:\n // bool rec(string s1,string s2){\n // int n=s1.size();\n // if(s1==s2) return 1;\n // bool ans=0;\n // for(int i=1;i<n;i++){\n // string s3=s1.substr(0,i);\n // string s4=s1.substr(i,n-i);\n // string s5=s2.substr(...