id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "constexpr size_t npos = -1;\n\npair<char,size_t> invalid = {'/',npos};\n\ntemplate<typename T>\nbool is_invalid(const pair<T,size_t> ans)\n{\n return ans.second==npos;\n}\n\npair<char, size_t> try_parse_char(const string& str, size_t i,char c){\n if(i>=str.size()) return invalid;\n if(c!=str[i]) r...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<int> rep;\n stack<string> ch;\n s = \"1[\" + s + ']';\n for(int i = 0; i < s.length(); i++) {\n cout<<\"s- \"<<s[i]<<\" \";\n if(isdigit(s[i])) {\n int num = 0;\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string multiplyStr(string s,int num){\n string str = \"\";\n while(num){\n str = str + s;\n num--;\n }\n return str;\n }\n void makeNumberAndPush(string s, int *idx,stack <int> &numStk){\n string num = \"\";\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n cout << s << endl;\n\n if(s.empty()){\n return \"\";\n } \n\n if(s[0] >= 'a' && s[0] <= 'z'){\n string sub;\n int i = 0;\n while(s[i] >= 'a' && s[i] <= 'z'){\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "#define PB push_back\nclass Solution {\npublic:\n string decodeString(string s) {\n vector<int> ns;\n vector<char> cs;\n string num;\n for(auto ch : s) {\n if(ch=='[') {\n cs.PB(ch);\n ns.PB(stoi(num));\n num=\"\"s;\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<int> st;\n for (int i = 0; i < s.size(); i++) {\n if (s[i] != ']') {\n st.push(s[i]);\n continue; \n }\n // pop till '[' then digits\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Node\n{\nprivate:\n char m_char;\n int m_num;\n vector<Node*> m_childNodes;\n\n bool isDigit(char c)\n {\n int digit = (int) c;\n if (digit >= 48 & digit <= 57)\n {\n return true;\n }\n return false;\n }\n\n int getNumFromStack(stack<...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\nprivate:\n string s;\n unordered_map<int, int> leftToRight, rightToLeft;\n\n void processBrackets() {\n stack<int> stk;\n for (int i = 0; i < s.length(); i++) {\n if (s[i] == '[') stk.push(i);\n else if (s[i] == ']') {\n leftToRi...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "/*\n\n3[a2[c]]\n\nupon finding `<digit>[,`\ncontinue reading and record `<inner>]`\n\nrun decode on the inner part\noutput += <digit> * innerdecoded\n\n*/\n\nclass Solution {\npublic:\n std::string decodeString(std::string s) {\n return dsr(s.cbegin(), s.cend());\n }\n std::string dsr(auto ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string convert(string n,string s){\n string temp=\"\";\n for(int i=0;i<stoi(n);i++){\n temp+=s;\n }\n return temp;\n }\n string decodeString(string s) {\n stack<int>st;\n string ans=\"\";\n for(int i=0;i<s.size...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\nstring convert(string n,string s){\n string temp=\"\";\n for(int i=0;i<stoi(n);i++){\n temp+=s;\n }\n return temp;\n }\n string decodeString(string s) {\n // using recursion : \n // int i=0;\n // return helper(i,s)...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\nint stringToInteger(string s) {\n int ans = 0;\n for (char nxt : s) {\n ans *= 10;\n ans += nxt - '0';\n }\n return ans;\n }\n\n public:\n string decodeString(string s) {\n string ans = \"\";\n int prev = 0;\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\n std::string result;\n stack<string> St;\n int N;\n string expand(string s, int num){\n string result;\n for (int i=0; i<num; ++i){\n result=result+s;\n }\n return result;\n }\n\n int find_end_of_string(string s){\n int count...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n if (s.size() == 0) return \"\";\n string ans;\n\n int i = 0;\n\n while (i < s.size()) {\n int numRep = 0;\n\n while (isdigit(s[i])) {\n numRep = (numRep * 10) + (s[i] - '0');\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n std::string result{\"\"};\n std::string subString{\"\"};\n bool inSub{false};\n size_t nBracket{0};\n size_t nRepetition{0};\n for(auto iter = s.begin(); iter != s.end(); iter++){\n if('0' ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n map<int, int> m;\n\n string decodeString(string s) {\n m.clear();\n stack<int> st;\n s=\"[\"+s+\"]\";\n for (int i =0;i<s.size();i++)\n {\n if (s[i] == '[')\n {\n st.push(i);\n }\n el...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "#include <cctype> // For isdigit()\n\nclass Solution {\npublic:\n string decodeString(string s) {\n\n if (!s.contains('[')) {\n return s;\n }\n\n std::stack<int> stacknums;\n std::stack<string> stackstrings;\n std::string result = \"\";\n int n = 0;\n...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string str) {\n \n cout << str << endl;\n \n if (str.size() == 0) return \"\";\n\n int s = -1;\n int e = -1;\n int n = str.size();\n int c = 0;\n int ns = n;\n string num = \"\";\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) \n {\n if(s.empty()) return \"\";\n \n std::string res = \"\";\n int i = 0, j = 0;\n \n while( j < s.size() )\n {\n while( j < s.size() && isalpha(s[j]) ) \n j++;\n\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string str) {\n \n cout << str << endl;\n \n if (str.size() == 0) return \"\";\n\n int s = -1;\n int e = -1;\n int n = str.size();\n int c = 0;\n int ns = n;\n string num = \"\";\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string str) {\n \n cout << str << endl;\n \n if (str.size() == 0) return \"\";\n\n int s = -1;\n int e = -1;\n int n = str.size();\n int c = 0;\n int ns = n;\n string num = \"\";\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<char> st;\n for(int i = 0; i < s.size(); ++i){\n if(s[i] == ']'){\n stack<char> aux;\n while(st.top() != '['){\n aux.push(st.top());\n st.pop()...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<char> st;\n for(int i = 0; i < s.size(); ++i){\n if(s[i] == ']'){\n stack<char> aux;\n while(st.top() != '['){\n aux.push(st.top());\n st.pop()...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<char> st;\n for(int i = 0; i < s.size(); ++i){\n if(s[i] == ']'){\n stack<char> aux;\n while(st.top() != '['){\n aux.push(st.top());\n st.pop()...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<char> st;\n for(int i = 0; i < s.size(); ++i){\n if(s[i] == ']'){\n stack<char> aux;\n while(st.top() != '['){\n aux.push(st.top());\n st.pop()...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\n// find si and ei to solve\n pair<int,int> getIndexesToSolve(string s) {\n pair<int,int> indexes;\n int bracketStart = 0;\n for(int i=0;i<s.length();i++) {\n if(s[i]== '[') {\n bracketStart = i;\n }\n if(s[i]==']') {\...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "\nclass Solution {\npublic:\n string decodeString(string s) {\n stack<char> stack;\n for (int i = 0; i < s.length(); i++) {\n if (s[i] == ']') {\n string decodedString = \"\";\n // get the encoded string\n while (stack.top() != '[') {...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<char>st;\n int n=s.size();\n string temp=\"\";\n for(int i=0;i<n;i++){\n if(s[i]==']'){\n string t=\"\";\n while(!st.empty() && st.top()!='['){\n t=...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n int sz = s.length();\n stack<char> st;\n std::string res;\n for(auto ch : s){\n if(ch!=']'){\n st.push(ch);\n }else{\n std::string str{\"\"};\n whi...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<char> st;\n for(int i=0;i<s.length();i++){\n if(s[i] == ']'){\n string res = \"\";\n while(st.top() != '['){\n res += st.top();\n st.pop();\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<char> st;\n\n for(char ch:s){\n if(ch!=']'){\n st.push(ch);\n continue;\n }\n\n string innerString = \"\";\n while(!st.empty()&&st.top()!='['){\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<char> st;\n for(char ch: s)\n {\n if(ch == ']')\n {\n string temp = \"\";\n while(st.top() != '[')\n {\n temp=st.top()+temp;\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s){\n int n = s.length();\n stack<char> st;\n string ans = \"\";\n \n for (int i = 0; i < n; i++){\n if (s[i] == ']') {\n string repeat = \"\";\n while(st.top() != '['){\n ...
394
<p>Given an encoded string, return its decoded string.</p> <p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p> <p>You may assume th...
3
{ "code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<char> st;\n string ans=\"\";\n for(int i=0;i<s.size();i++) {\n if(s[i]==']') {\n while(st.size()>0 && st.top()!='[') {\n ans=st.top()+ans;\n st.pop();\...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
0
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int countMap[26];\n int maxUnique = getMaxUniqueLetters(s);\n int result = 0;\n for (int currUnique = 1; currUnique <= maxUnique; currUnique++) {\n // reset countMap\n memset(countMap,...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
0
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n /* [a:3]\n [b:2]\n [c:1]\n */\n vector<int> map(26,0);\n for(auto c: s){\n map[c-'a']++;\n }\n for(int sz = s.size(); sz > 0; sz--){\n for(int i = s.s...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
1
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int n=s.size();\n // unordered_set<char>st;\n vector<int>dict(26,0);\n int ans=0;\n int maxunique=0;\n for(int i=0;i<s.size();i++){\n if(dict[s[i]-'a']==0)maxunique++;\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
1
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int n = s.size();\n if(k>n || n==0) return 0;\n if(n <= 1) return n;\n unordered_map<char,int> mp;\n for(char c : s){\n mp[c]++;\n }\n\n int l = 0;\n while(l<n && mp[s...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int ans = 0;\n int n = s.size();\n vector<vector<int>> dp;\n vector<int> charCnt(26, 0);\n dp.push_back(charCnt);\n for(const char& c: s) {\n ++charCnt[c-'a'];\n dp.push_...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\nprivate:\n vector<vector<int>> dp;\npublic:\n int longestSubstring(string s, int k) {\n int ans = 0;\n int n = s.size();\n vector<int> charCnt(26, 0);\n dp.push_back(charCnt);\n for(const char& c: s) {\n ++charCnt[c-'a'];\n dp...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int K) {\n \n int n = s.length();\n int ans = 0;\n vector<int> arr[100100];\n vector<int> fre(28,0);\n\n for(int i=0;i<n;i++)\n {\n fre[s[i]-'a']++;\n arr[i] = fre;\n }\n\n for(int...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\npublic:\n int ans = 0;\n void solve(string &s, int &k, int begin, int end, vector<int> &record){\n // priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> small_mp;\n unordered_map<int, int> small_mp;\n int index = end;\n for(int i = begin; i...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\npublic:\n int findLongest(int start, int end, int k,string &s){\n vector<int> cnt(26,0);\n for(int i=start;i<end;++i) cnt[s[i]-'a']++;\n for(int i=start;i<end;++i){\n if(cnt[s[i]-'a'] < k){\n return max(findLongest(start,i,k,s),findLongest...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n unordered_map<char,int> cnt;\n for (char c : s) cnt[c]++;\n int res = 0;\n bool foundLess = false;\n for (auto [c,v] : cnt) {\n if (v < k) {\n foundLess = true;\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int res = 0;\n int n = s.size();\n for(int i = 0; i <= n - k; i++){\n unordered_map<char,int> mp;\n int mask = 0;\n int mxidx = i;\n for(int j = i; j < n; ++j){\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n \n int n = s.size(), lastIndex = -1, ans = 0;\n \n while(lastIndex < n-1){\n int i = lastIndex+1;\n int currLastIndex = lastIndex;\n\n unordered_map<int,int> count;\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\npublic:\nbool valid(const map<char,int>& m,int& value) {\n for (const auto& elem : m) {\n if (elem.second < value) {\n return false;\n }\n }\n return true;\n}\n int longestSubstring(string s, int k) {\n int ans=0;\n if(k>s.length())return...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\npublic:\n bool isValid(map<char,int>&mpp, int k) {\n for(auto& it: mpp) {\n if(it.second < k) return false;\n }\n return true;\n }\n int longestSubstring(string s, int k) {\n if(k>s.size() || k<=0) return 0;\n int maxLen = 0;\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\npublic:\n // Helper function to divide and conquer\n int longestSubstringHelper(const string& s, int k, int start, int end) {\n if (end - start < k) return 0; // If the substring length is smaller than k, it can't be valid\n \n unordered_map<char, int> freqMap;\...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
2
{ "code": "class Solution {\npublic:\n int divideAndConquer(const string& s, int start, int end, int k) {\n if (end - start < k) return 0; // If the length is less than k, it's not possible\n\n // Frequency map for the current substring\n unordered_map<char, int> freq;\n for (int i ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int ans=0;\n for(int i=0;i<s.size();i++){\n vector<int>fq(26,0);\n vector<int>vis(26,0);\n unordered_map<char,int>m;\n for(int j=i;j<s.size();j++){\n fq[s[j...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n\n int dfs(const string& s, int l, int r, int k) {\n // std::cout << \"dfs l = \" << l << \" r = \" << r << std::endl;\n unordered_map<char, int> cnt;\n unordered_set<char> removed_char;\n for (char x = 'a'; x <= 'z'; ++x) {\n cnt[x] = 0;...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int n = s.length();\n if(k==1){\n return n; \n }\n vector<vector<int>> ocurr(26);\n for(int i=0; i<n; i++){\n ocurr[s[i]-'a'].push_back(i);\n }\n int ans =0; \n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n if(s.length()==0 || k>s.length()) return 0;\n int freq[26]={0};\n for(auto ch:s){\n freq[ch-'a']++;\n }\n int i=0;\n int len=0;\n while(i<s.length() && freq[s[i]-'a']>=k){\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n //If string shorter than k return 0\n if(s.size() < k){\n return 0;\n }\n\n //Get a count of every character in string\n int count[26] = {0};\n int def = 'a';\n for(char char...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n //If string shorter than k return 0\n if(s.size() < k){\n return 0;\n }\n\n //Get a count of every character in string\n int count[26] = {0};\n int def = 'a';\n for(char char...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int n=s.size();\n int mp[26]={};\n if(n==0) return 0;\n\n for(int i=0;i<n;i++){\n mp[s[i]-'a']++;\n }\n\n int i=0;\n while(i<n && mp[s[i]-'a']>=k)i++;\n if(i==n) retur...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n // cut the string at char num < k\n // and keep doing the same for the cutted sub string\n // until find the substring that can't be cut, return the substring length\n // or when substring len < k, return -1;\n int longestSubstring(string s, int k) {\n \n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n // base case\n if(s.size()==0) return 0;\n\n\n int map[26] = {};\n for(int i=0;i<s.size();i++){\n map[s[i]-'a']++;\n }\n\n int i=0;\n while(i<s.size() && map[s[i]-'a']>=k) i++;\n if(i==s.size()) return s...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int n = s.size(), i = 0, ans = 0;\n if(!n || n < k) return 0;\n vector<int> freq(26, 0);\n for(auto &ch : s) freq[ch - 'a']++;\n while(i < n && freq[s[i]-'a'] >= k) i++;\n if(i == n) return n;...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int n = s.size();\n if (n < k)\n return 0;\n vector<int> preCount(26, 0);\n for (auto& el : s)\n preCount[el-'a']++;\n for (int i = 0; i < n; i++)\n if (preCount[s[i]...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int f(string s, int k) {\n if(s.size() < k) return 0;\n vector<int> m(26, 0);\n for(auto ch: s) {\n m[ch-'a']++;\n }\n int i=0; \n while(i<s.size() && m[s[i]-'a'] >= k) {\n i++;\n }\n if(i==s.size()...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int n = s.size();\n if (n < k)\n return 0;\n vector<int> preCount(26, 0);\n for (auto& el : s)\n preCount[el-'a']++;\n bool flag = 1;\n for (int i = 0; i < n; i++) {\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int n = s.size();\n if (n < k)\n return 0;\n vector<int> preCount(26, 0);\n for (auto& el : s)\n preCount[el-'a']++;\n for (int i = 0; i < n; i++)\n if (preCount[s[i]...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n bool condition(unordered_map<char, int> mp, int k){\n for(auto i=mp.begin(); i!=mp.end(); i++){\n if(i->second<k) return false;\n }\n return true;\n }\n bool kReached(unordered_map<char, int> mp, int k){\n for(auto i=mp.begin(); i!...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n bool condition(unordered_map<char, int> mp, int k){\n for(auto i=mp.begin(); i!=mp.end(); i++){\n if(i->second<k) return false;\n }\n return true;\n }\n bool kReached(unordered_map<char, int> mp, int k){\n for(auto i=mp.begin(); i!...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n if(s.length() == 0 && k > 0)\n {\n return 0;\n }\n if(k == 0)\n {\n return s.length();\n }\n vector<int> freq(26);\n for(int i = 0; i < s.length(); i++)\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int ans = 0;\n int n = s.size();\n vector<int> c(26, 0);\n \n for (auto x : s) {\n c[x - 'a']++;\n }\n\n for (int i = 0; i < n; ++i) {\n if (c[s[i] - 'a'] < k) {\...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n vector<int> v(26,0);\n for(int i = 0 ;i <s.size();i++) {\n v[s[i] - 'a']++;\n }\n\n for(int i = 0;i<s.size();i++){\n if(v[s[i] - 'a'] < k){\n int left = longestSubstring...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n if(s.size() == 0 || k > s.size()) return 0;\n if(k == 0) return s.size();\n \n unordered_map<char,int> Map;\n for(int i = 0; i < s.size(); i++){\n Map[s[i]]++;\n }\n \...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n if(s.size() == 0 || k > s.size()) return 0;\n if(k == 0) return s.size();\n \n unordered_map<char,int> Map;\n for(int i = 0; i < s.size(); i++){\n Map[s[i]]++;\n }\n \n...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n if(s.size() == 0 || k > s.size()) return 0;\n if(k == 0) return s.size();\n \n unordered_map<char,int> Map;\n for(int i = 0; i < s.size(); i++){\n Map[s[i]]++;\n }\n \...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n unordered_map<char,int>mp;\n for(int i=0;i<s.size();i++){\n mp[s[i]]++;\n }\n int l=0;\n while(l<s.size() and mp[s[l]]>=k)l++;\n if(l==s.size())return s.size();\n\n int left ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n if(s.empty() ) return 0;\n if(k > s.size()) return 0;\n unordered_map<char, int> mp;\n for(char c: s) mp[c]++;\n\n int idx = 0 ;\n while(idx < s.size() && mp[s[idx]] >= k) idx++;\n\n //...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\n public:\n int longestSubstring(string s,int k){\n map<char,int>mp;\n for(int i=0;i<s.size();i++){\n mp[s[i]]++;\n }\n int j=0;\n while(j<s.size() && mp[s[j]]>=k){\n j++;\n }\n if(j==s.size())return j;\n i...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n map<char,int>mp;\n for(int i=0; i<s.size(); i++){\n mp[s[i]]++;\n }\n\n int j=0;\n while(j<s.size() and mp[s[j]]>=k){\n j++;\n }\n if(j==s.size()) retu...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n vector<int> cnt(256);\n for (char c : s) cnt[c]++;\n int res = 0, break_point = 0;\n bool pass = true;\n for (int i = 0; i < s.size(); i++) {\n if (cnt[s[i]] < k) {\n break_...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int solve(string s, int k, int start, int end) {\n if (start == end) return 0;\n vector<int> v(26, 0);\n for(int i = start; i < end; i++) v[s[i] - 'a']++;\n bool check = false;\n for(int a: v) {\n if (a > 0 && a < k) {\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int solve(string s, int k, int start, int end) {\n if (start == end) return 0;\n vector<int> v(26, 0);\n for(int i = start; i < end; i++) v[s[i] - 'a']++;\n bool check = false;\n for(int a: v) {\n if (a > 0 && a < k) {\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n return longestSubstring(s, k, 0, s.size());\n }\n\n int longestSubstring(string s, int k, int start, int end) {\n if(start > end) return 0;\n vector<int> cnt(26);\n for(int i = start; i < end; i++) {\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n return longestSubstring(s, k, 0, s.size());\n }\n\n int longestSubstring(string s, int k, int start, int end) {\n if(start > end) return 0;\n vector<int> cnt(26);\n for(int i = start; i < end; i++) {\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n vector<int> count(26,0);\n int n=s.size();\n int res=0;\n int cnt=0;\n unordered_set<char>not_valid;\n for(int i=0;i<n;i++)\n {\n count[int(s[i])-97]++;\n }\n f...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int n = s.length();\n if(n<k) return 0;\n int freq[26];\n memset(freq, 0, sizeof(freq));\n\n for(int i=0;i<n;i++){\n freq[s[i]-'a'] +=1;\n } \n\nfor(int i=0;i<26;i++){\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n bool helper(string str,int size,int k){\n unordered_map<char,int>mp;\n for(int i =0;i<size;i++){\n mp[str[i]]++;\n }\n bool flag = true;\n for(auto x : mp){\n if(x.second<k){\n flag = false;\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int freq[26];\n for(int i=0; i<26; i++)\n freq[i] = 0;\n for (char ch:s)\n freq[ch-'a']++;\n \n bool s_is_valid = true;;\n int res = 0;\n for (int end=0; end<s.len...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n unordered_set<int> lengths;\n int longestSubstring(string s, int k){\n aux_longestSubstring(s, k);\n int max_len = 0;\n for(auto iter=lengths.begin(); iter!=lengths.end(); ++iter){\n if(max_len < *iter){\n max_len = *iter;\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n int i = findUnmetIndex(s, k);\n if(i == -1) return s.size();\n int leftL = longestSubstring(s.substr(0, i), k);\n int rightL = longestSubstring(s.substr(i + 1), k);\n return max(leftL, rightL);\n\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n if (s.size() < k) return 0;\n vector<char> myVector(s.begin(), s.end());\n unordered_map<char,int>hash;\n for(char c:myVector)\n {\n hash[c]++;\n }\n \n for (int i = 0; i <...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n if (s.length() == 0 or s.length() < k) {\n return 0;\n } \n if (!k) {\n return s.length();\n }\n map<char, int> m;\n for (int i = 0; i < s.length(); i++) {\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int func(int i,int j,int k,string s)\n {\n if((j-i+1)<k)\n return 0;\n vector<int> vec(26,0),start(26,-1),end(26,-1);\n for(int p=i;p<=j;p++)\n {\n if(vec[s[p]-'a']==0)\n start[s[p]-'a']=p;\n end[s...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n\n if(k==1){\n return s.length();\n }\n\n int ans = 0;\n\n \n for(int i=0; i<s.length(); i++){\n string temp = \"\";\n int charFreq[26]={0};\n for(int j=i; j...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\nint max(int a,int b){\n if(a>b)return a;\n else return b;\n}\n int longestSubstring(string s, int k) {\n int mx=0;\n int n=s.size();\n for(int i=0;i<n;i++){\n string ans=\"\";\n int count[26]={0};\n for(int j=i;j<n;j++){...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int mini_ele(vector<int>& map){\n int ans =1e9;\n for(int i=0;i<map.size();i++){\n if(ans>map[i] and map[i]!=0){\n ans = map[i];\n }\n }\n return ans;\n }\n int longestSubstring(string s, int k) {\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n bool secondCheck(const string& str, int k) {\n if (str.length() < k) {\n return false;\n }\n vector<int> alphabets(26, 0);\n for (char ch : str) {\n alphabets[ch - 'a']++;\n }\n for (int count : alphabets) {\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int max(int &a,int b)\n {\n return a>b?a:b;\n }\n int longestSubstring(string s, int k) {\n unordered_map<char,int> mp;\n int maxi=0;\n for(int i=0;i<s.size();i++)\n {\n mp.clear();\n string tmp=\"\";\n ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n unordered_map<char,int> mp;\n int maxi=0;\n for(int i=0;i<s.size();i++)\n {\n mp.clear();\n string tmp=\"\";\n for(int j=i;j<s.size();j++)\n {\n tm...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\nprivate:\n bool solve(unordered_map<char,int>& mp, int k){\n for(auto it: mp){\n if(it.second < k) return false;\n }\n return true;\n }\npublic:\n int longestSubstring(string s, int k) {\n int n = s.size();\n\n\t\tint maxi = 0;\n\t\tfor(int ...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\n bool check(unordered_map<char,int> freq, int k) {\n for (auto p:freq){\n if (p.second<k)\n return false;\n }\n return true;\n }\npublic:\n int longestSubstring(string s, int k) {\n int n=s.length();\n unordered_set<cha...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n return longestSubstringUtil(s, k, 0, s.length());\n\n \n }\nprivate:\n int longestSubstringUtil(string s, int k, int start, int end) {\n if (end - start < k) return 0;\n \n int count[26] = {0};...
395
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p> <p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>...
3
{ "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n return lSFun(s,k,0,s.size()-1);\n }\n\n int lSFun(string s, int k, int start, int end){\n if(end-start+1<k){\n return 0;\n }\n\n int count[26]={0};\n for(int i=start; i<=end; i++){\n...