id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
2
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n int xor_sum = 0;\n int n = arr.size();\n for(int i=0;i<n;i++){\n xor_sum ^= arr[i] ^ target[i];\n }\n if(xor_sum!=0)\n return false;\n unordered_map<int,...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
2
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n unordered_map<char, int> hash;\n for(auto it: target){\n hash[it]++;\n }\n\n for(auto it: arr){\n hash[it]--;\n }\n\n for(auto it: hash){\n if...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
2
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n multiset<int>s;\n for(int i=0;i<arr.size();i++){\n s.insert(arr[i]);\n }\n for(int i=0;i<target.size();i++){\n auto it=s.find(target[i]);\n if(it==s.end()) ...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
2
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n multiset<int>s;\n for(int i=0;i<arr.size();i++){\n s.insert(arr[i]);\n }\n for(int i=0;i<target.size();i++){\n auto it=s.find(target[i]);\n if(it==s.end()) ...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
2
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n //Array initialization\n unordered_map<int, int> mp;\n\n //store \"target\" array in map\n for(int i = 0; i < target.size(); i++)\n {\n mp[target[i]]++;\n }\n\n ////...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
2
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n unordered_map<int,int> int_ct;\n for(int i:target){\n if(int_ct.contains(i)){\n int_ct[i]++;\n }\n else{\n int_ct[i]= 1;\n }\n ...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
2
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n unordered_map<int,int>mp;\n for(int &num : target){\n mp[num]++;\n }\n for(int &num : arr){\n if(mp.find(num) == mp.end()){\n return false;\n ...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
2
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n unordered_map<int,int> mpp;\n for(int i = 0; i < target.size() ; i++)\n {\n mpp[target[i]]++;\n }\n\n for(int i = 0 ; i < target.size() ; i++)\n {\n if(m...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
2
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n unordered_map<int,int> mp;\n for(int i=0;i<target.size();i++){\n mp[target[i]]++;\n }\n for(int i=0;i<target.size();i++){\n if(mp.find(arr[i])==mp.end())\n ...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
3
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n unordered_map<int,int> m;\n for(int t:target){\n m[t]++;\n }\n for(int a: arr){\n if(!m.count(a)) return false;\n m[a]--;\n if(m[a]<0) return fal...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
3
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n unordered_map<int, int> freq;\n for (int i = 0; i < target.size(); i++) {\n freq[target[i]]++;\n freq[arr[i]]--;\n }\n for (auto f:freq) {\n if (f.second !=...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
3
{ "code": "static const int _ = []() {\n std::ios_base::sync_with_stdio(0);\n std::cin.tie(0);\n return 0;\n}();\n\n#pragma GCC optimize(\"Ofast\")\n\nclass Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n map<int, int> counts;\n\n for (int i : target) counts[...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
3
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n int n1=target.size();\n int n2=arr.size();\n if(n1!=n2){\n return false;\n }\n set<int> s;\n set<int> st;\n \n for(int i=0;i<n1;i++){\n s.i...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
3
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n sort(arr.rbegin(),arr.rend());\n sort(target.rbegin(),target.rend());\n return target==arr;\n }\n};", "memory": "20600" }
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
3
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n std::unordered_map<int, size_t> count;\n\n for (int i : target) {\n count[i]++;\n }\n\n for (int i : arr) {\n count[i]--;\n }\n\n for (auto& [_, v] : cou...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
3
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n unordered_map<int,int>h1;\n unordered_map<int,int>h2;\n int count=0;\nfor(int i=0;i<target.size();i++){\nh1[target[i]]++;\n\nh2[arr[i]]++;\n\n}\nfor(int i=0;i<target.size();i++){\nif (h1[target[i]...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
3
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n unordered_map<int, int> mpTar, mpArr;\n\n for(int i = 0; i < target.size(); i++) {\n mpTar[target[i]]++;\n }\n\n for(int i = 0; i < arr.size(); i++) {\n mpArr[arr[i]]+...
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
3
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n map<int,int> m1,m2;\n for(auto i=0;i<arr.size();i++)\n {\n m1[target[i]]++;\n m2[arr[i]]++;\n }\n return m1==m2;\n }\n};", "memory": "20900" }
1,556
<p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make </em><code>arr</code><em...
3
{ "code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n // Dictionary to maintain frequency count for arr\n unordered_map<int, int> arrFreq;\n for (int num : arr) {\n arrFreq[num]++;\n }\n\n // Dictionary to maintain frequency ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "#include <iostream>\n#include <random>\n#include <array>\n#include <vector>\n#include <string>\n#include <map>\n#include <unordered_map>\n#include <set>\n#include <unordered_set>\n#include <algorithm>\n#include <functional>\n#include <queue>\n#include <stack>\n#include <bitset>\n\n#include <math.h>\n\nusin...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "#include <iostream>\n#include <random>\n#include <array>\n#include <vector>\n#include <string>\n#include <map>\n#include <unordered_map>\n#include <set>\n#include <unordered_set>\n#include <algorithm>\n#include <functional>\n#include <queue>\n#include <stack>\n#include <bitset>\n\n#include <math.h>\n\nusin...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int tot = 1<<k;\n int n = s.length();\n if(n<tot) return false;\n int bitmask = tot-1;\n vector<bool> st(tot);\n int hash = 0, cnt = 0;\n for(int i=0; i<n; i++){\n hash = ((hash<...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\n public:\n bool hasAllCodes(string s, int k) {\n const int n = 1 << k;\n if (s.length() < n)\n return false;\n\n // used[i] := true if i is a substring of `s`\n vector<bool> used(n);\n\n int window = k == 1 ? 0 : stoi(s.substr(0, k - 1), nullptr, 2);\n for (int i =...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n=s.size();\n int m=1<<k;\n vector<bool>vis(m,0);\n int curr=0;\n if(n<k) return 0;\n for(int i=0;i<k;i++){\n bool d=s[i]-'0';\n curr=(curr<<1)+d;\n }\n vis...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n vector<bool> v(1<<k);\n int x = 0,i,n=s.length();\n for(i = 0; i < n;i++){\n x <<= 1;\n if(s[i]=='1')x |= 1;\n if(i>=k-1){\n v[x] = 1;\n x |= (1<<(k-1));\...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "// class Solution {\n// public:\n// bool hasAllCodes(string s, int k) {\n\n// int n = s.length();\n\n// string subset;\n\n// unordered_set<string> myset; // size()\n\n// for (int i=0; i<=(n-k); i++){\n\n// for (int j=0; j<k; j++){\n\n// subset...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "// class Solution {\n// public:\n// bool hasAllCodes(string s, int k) {\n\n// int n = s.length();\n\n// string subset;\n\n// unordered_set<string> myset; // size()\n\n// for (int i=0; i<=(n-k); i++){\n\n// for (int j=0; j<k; j++){\n\n// subset...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "// class Solution {\n// public:\n// bool hasAllCodes(string s, int k) {\n\n// int n = s.length();\n\n// string subset;\n\n// unordered_set<string> myset; // size()\n\n// for (int i=0; i<=(n-k); i++){\n\n// for (int j=0; j<k; j++){\n\n// subset...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n = s.size();\n if ((1 << k) > (n - k + 1)) return false;\n int cur = 0;\n for (int i = 0; i < k; i++) {\n cur += (s[k - i - 1] - '0') * (1 << i);\n }\n unordered_set<int> us;\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int code = 0;\n int n = s.size();\n if (n - k + 1 < 1 << k) return false;\n for (int i = 0; i < k; i++) code = code * 2 + (s[i] - '0');\n unordered_set<int> codes({code});\n for (int i = 0, j = k;...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n //cout<<((int)s.length()-k+1)<<\" < \"<<(int)pow(2,k);\n if((int)s.length()-k+1 < (int)pow(2,k)) return false;\n unordered_map<int,int> m;\n int n=0;\n for(int i=0; i<k ; i++){\n n += (s[i]-'0...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n set<int> st;\n int f=0;\n int n=s.length();\n // checking if number of substrings of length k is less than required number\n // then answer will be false or 0 \n int requiredCounts=1<<k;\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "/*\n * @lc app=leetcode id=1461 lang=cpp\n *\n * [1461] Check If a String Contains All Binary Codes of Size K\n */\n\n// @lc code=start\n#include <bits/stdc++.h>\n// #include <boost/multiprecision/cpp_int.hpp>\n// using namespace boost::multiprecision;\nusing namespace std;\n#define ll long long int\n// #d...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n \n bool hasAllCodes(string s, int k) {\n int n=s.length();\n if(n<k) return false;\n unordered_set<int>set;\n int bitmask=(1<<k)-1;\n int sum=0;\n for(int i=0;i<k;i++){\n sum|=((s[i]-'0')<<(k-i-1));\n }\n s...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n if(k == 0) {\n return false;\n }\n\n int n = s.size();\n int num_combinations = (1 << k);\n\n unordered_set<int> set;\n for(int i = 0; i <= n - k; i++) \n {\n int num ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "// Constraints:\n// 1 <= s.length <= 5 * 105\n// s[i] is either '0' or '1'.\n// 1 <= k <= 20\n\nclass Solution\n{\npublic:\n bool hasAllCodes(string s, int k)\n {\n int n = s.size();\n\n if (n < k)\n {\n return false;\n }\n\n int mask = 0;\n int va...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n = s.size();\n if(n < k) {\n return false;\n }\n int mask = (2 << k-1) - 1;\n vector<int> mp(mask + 1, 0);\n int rh = 0;\n for(int i = 0; i < k; i++) {\n rh <<= 1...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n \n int i=0, j=0;\n int n=s.length();\n unordered_set<int>us;\n string sub_str=\"\";\n while(j<n)\n {\n sub_str+=s[j];\n if((j-i)+1==k) {\n //\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n = s.size();\n if(n < k || k == 20) return false;\n map<int, bool> vis;\n int cnt = 0, eq = 0, mult = 1;\n for(int i = 0; i < k; i++){\n int bit = (s[i] - '0');\n eq = (2 * eq)...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n int check(string& s, int& i,int& k){\n int temp = 0;\n for(int t = i; t < i +k;t++){\n if(s[t] == '0'){\n temp = temp*2;\n }else{\n temp = temp*2 +1;\n }\n }\n return temp;\n }\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) \n {\n long long n = s.size(), num = 0, div = pow(2, k);\n vector<int> buf (pow(2, k));\n\n for(int i = 0, j = 0; i < n; i++)\n {\n num *= 2;\n num += s[i] - 48;\n\n while(i - j ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s1, int k) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n set<int> s;\n int tot = pow(2,k);\n if(s1.size()<k){\n return false;\n }\n int val=0;\n\n for(int i=0; i<k; i++){\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n set<int>st;\n int len = (int)s.size();\n int i = 0;\n int j = 0;\n \n int num = 0;\n while(j<len){\n int value = s[j]-'0';\n num <<= 1;\n num |= value;\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n if(k>s.size())\n return false;\n \n set<int> st;\n for(int i=0;i<=s.size()-k;i++){\n int decNum = 0 , bits= k-1;\n for(int j=i;j<i+k;j++){\n // hash will be equa...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int ones = pow(2, k) - 1;\n int soFar = 0;\n set<int> found;\n for (int i = 0; i < s.size(); i++) {\n soFar <<= 1;\n soFar &= ones;\n soFar |= (s[i] == '1');\n if (i ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n long long x=pow((long long)2,(long long )k);\n if(s.size()<x) return false;\n unordered_set<long long> ss;\n for(int i=0;i+k-1<s.size();i++)\n {\n ss.insert(stol(s.substr(i,k)));\n }\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\nprivate :\n // this is piegon hod principle\npublic:\n bool hasAllCodes(string s, int k) {\n // k = size of substrings\n long long x=pow((long long)2,(long long )k); // 2 ki power K substrings are possible.\n if(s.size()<x) return false;\n unordered_set<long...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n=pow(2,k); //for k ther will be 2^k possible binary codes\n vector<int> v(n,0); //Initialise with zero , change 0 to 1 if this binary code is present in the string\n \n int m=s.length();\n i...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n=pow(2,k); //for k ther will be 2^k possible binary codes\n vector<int> v(n,0); //Initialise with zero , change 0 to 1 if this binary code is present in the string\n \n int m=s.length();\n i...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n=1<<k;\n /* vector<int>v(n,0);\n // this vector will contain all the elements that are to be checked\n if(n>s.length())return false;\n int val=0;\n for(int i=0;i<k;i++){\n int a=s[i...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n if(s.size() < (pow(2, k) + k - 1))\n return false;\n string currcode = \"\";\n uint index = 0;\n while(index < k)\n currcode += s[index++];\n unordered_set<string> allcodes;\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n\n /*Gernating A Substring Can be costilier */\n ios_base::sync_with_stdio(false);\n cin.tie(0), cout.tie(0);\n\n int N=s.length();\n string sub=\"\";\n vector<bool>numtocheck(pow(2,k),false);\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n\n /*Gernating A Substring Can be costilier */\n ios_base::sync_with_stdio(false);\n cin.tie(0), cout.tie(0);\n\n int N=s.length();\n string sub=\"\";\n vector<bool>numtocheck(pow(2,k),false);\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) \n {\n int val = pow(2 , k);\n if(s.size() - k + 1 < val) return false;\n set<string>st;\n for(int i = 0; i < int(s.size()) - k + 1; i++)\n {\n st.insert(s.substr(i , k));\n }\n if(st.siz...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) \n {\n int val = pow(2 , k);\n if(s.size() - k + 1 < val) return false;\n set<string>st;\n for(int i = 0; i < int(s.size()) - k + 1; i++)\n {\n st.insert(s.substr(i , k));\n }\n if(st.siz...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n auto binaryToInt = [](const string & binary) -> int {\n return std::stoi(binary, nullptr, 2);\n };\n\n unordered_set<int> st;\n\n for (int i = 0; i <...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n auto binaryToInt = [](const string & binary) -> int {\n return std::stoi(binary, nullptr, 2);\n };\n unordered_set<int> st;\n for (int i = 0; i < (int)s.size() - k + 1; i++) {\n string t =...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n \n int i=0, j=0;\n int n=s.length();\n unordered_set<int>us;\n while(j<n)\n {\n if((j-i)+1==k) {\n //\n string temps=s.substr(i,j-i+1);\n in...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n if(s.size()<k){\n return false;\n }\n int cnt=0;\n vector<int>check(pow(2,k),0);\n\n for(int i=0;i<s.size()-k+1;i++){\n string curr=s.substr(i,k);\n int sum=0;\n int n=1;\n \n...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "using ll = long long;\nclass Solution {\npublic:\n static const int base = 2;\n static const int maxn = 5 * 1e5 + 10;\n static const int MOD = 1e9 + 7;\n\n ll getHash(int l, int r, vector<ll> powers, vector<ll> hashs) {\n return (hashs[r] - (hashs[l - 1] * powers[r - l + 1]) % MOD + MOD)...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n unordered_map<string,int>mp;\n int requiredSubstring = (1<<k),n = s.size();\n if(n-k+1<requiredSubstring)\n return false;\n for(int i=0;i<=(n-k);i++)\n {\n mp[s.substr(i,k)]++;\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n unordered_map<string,bool>mp;\n int requiredSubstring = (1<<k),n = s.size();\n if(n-k+1<requiredSubstring)\n return false;\n for(int i=0;i<=(n-k);i++)\n {\n mp[s.substr(i,k)] = true;\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
0
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n vector<int> checker(pow(2,k),1);\n int n = s.length();\n if(n <= k) return false;\n int num = 0;\n string ss = s.substr(0,k);\n for(int i=k-1;i>=0;i--)\n if(ss[i]=='1') \n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n set<int>st; int n=s.size();\n for(int i=0;i<n-k+1;i++){\n string temp=s.substr(i,k);\n int x=0;\n for(int j=0;j<k;j++){\n int y=pow(2,j);\n y*=(temp[j]-'0');\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n set<int>st; int n=s.size();\n for(int i=0;i<n-k+1;i++){\n string temp=s.substr(i,k);\n int x=0;\n for(int j=0;j<k;j++){\n int y=pow(2,j);\n y*=(temp[j]-'0');\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n /*\n Constraints:\n - 1 <= s.length <= 5 * 10^5\n - s[i] is either '0' or '1'.\n - 1 <= k <= 20\n \n The first thing to check is if k is too large given the length of s. The string s cannot contain unlimited substrings.\n It can contain:\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n unordered_set<string> us;\n const int n = 1 << k;\n if (s.length() < n)\n return false;\n if(s.length() < 2*k) return false;\n for(int i = 0; i<s.length()-k+1 ; i++)\n {\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "\nclass Solution {\npublic:\n \n unordered_set<long long> rabin(string &yes,long long sz){\n long long h_s=0,h_p=0,p=256,p_p=1,i,j,m=1000000007;\n \n for(i=0;i<sz;i++){\n p_p=(p_p*p)%m;\n }\n unordered_set<long long>st;\n for(i=0;i<yes.size();i++){...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "\nclass Solution {\npublic:\n \n unordered_set<long long> rabin(string &yes,long long sz){\n long long h_s=0,h_p=0,p=256,p_p=1,i,j,m=1000000007;\n \n for(i=0;i<sz;i++){\n p_p=(p_p*p)%m;\n }\n unordered_set<long long>st;\n for(i=0;i<yes.size();i++){...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n \n unordered_set<long long> rabin(string &yes,long long sz){\n long long h_s=0,h_p=0,p=256,p_p=1,i,j,m=1000000007;\n \n for(i=0;i<sz;i++){\n p_p=(p_p*p)%m;\n }\n unordered_set<long long>st;\n for(i=0;i<yes.size();i++){\n...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "#pragma GCC optimize (\"O2\")\n\nauto _ = []() {\n ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);\n return 0;\n}();\nclass Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n = s.size();\n // If k is greater than the length of the string, it's impossible to have all codes\...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n = s.size();\n if(k > n) return false;\n int noOfCodes = 1 << k;\n unordered_set<string> st;\n string temp = s.substr(0,k);\n st.insert(temp);\n for(int i=k;i<n;i++){\n temp...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n = s.size();\n if(k > n) return false;\n int noOfCodes = 1 << k; // 2^k binary codes\n unordered_set<string> st;\n string temp = s.substr(0,k);\n st.insert(temp);\n for(int i=k;i<n;i++...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n = s.size();\n // If k is greater than the length of the string, it's impossible to have all codes\n if (k > n) return false;\n\n int i = 0, j = 0; // i is the start, j is the end of the window\n u...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "// class Solution {\n// public:\n// bool hasAllCodes(string s, int k) {\n// // if(s.length()<k){\n// return false;\n// }\n// int n=pow(2,k);\n\n// unordered_map<string,bool>mp;\n \n// for(int i=0;i<n;i++){\n// int t=i;...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n if (s.size() < k) return false;\n unordered_set<string>st;\n int total_numbers=pow(2,k);\n for(int i=0;i<=s.size()-k;i++){\n st.insert(s.substr(i,k));\n }\n return st.size()==total_numb...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n unordered_set<string> st;\n int n = s.size();\n \n // Loop through the string, extracting all substrings of length k\n for (int j = 0; j <= n - k; j++) {\n st.insert(s.substr(j, k)); // Extra...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n=s.size(); int j=0;if(k>n)return false;set<string>st;string ans=\"\";\n for(int i=0;i<s.size();i++){\n if(i-j+1<k){\n ans+=s[i];\n }\n if(i-j+1==k){\n ans+=s[i];\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
1
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n \tif(k > s.size()) return false;\n set<string>st;\n string temp;\n int size = 1<<k;\n for(int i =0;i<s.length();++i)\n {\n if(temp.length()<k)\n {\n temp.push_...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n\n long long int total=0;\n int j=0;\n map<vector<char>, int>mp;\n\n vector<char>temp;\n\n for(int i=0;i<s.size();i++)\n {\n temp.push_back(s[i]);\n if(temp.size()==k)\n {\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n if(s.size() < k) return false;\n set<string> hash;\n for(int i=0;i<=s.size() - k;i++) {\n hash.insert(s.substr(i,k));\n }\n long long res = 1;\n while(k--) res *= 2;\n return res...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n \n set<string> all_substrings;\n int total = 1 <<k; // this is equal to 2 power k (2^k)\n\n // get all the substring of len k and store it in a set\n for(int i =0;i+k<=s.length();i++){\n all_s...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "#include <unordered_set>\n#include <cmath>\n\nclass Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n = s.size();\n if (k > n) return false;\n\n long long val = pow(2, k) ;\n unordered_set<int> seen;\n\n string t = s.substr(0, k);\n int ans = sto...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n if(s.size()<k)\n return false;\n map<string, int>mp;\n string temp = \"\";\n for(int i = 0; i<k; i++)\n {\n temp+= s[i];\n }\n mp[temp]++;\n int i = 0;\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);\n\n if (s.length() < k)\n return false;\n\n unordered_map <string, bool> seen;\n\n int cnt = 1;\n string tmp = \"\";\n\n for (in...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n unordered_map<string,int>mp;\n string ok = \"\";\n for(int i = 0; i < s.size(); i++){\n ok += s[i];\n if(ok.size() > k){\n ok.erase(0,1);\n }\n if(ok.size() =...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n if(k>s.size()) return false;\n map<string, int>mp;\n for(int i = 0; i<=s.size()-k; i++)\n mp[s.substr(i,k)]++;\n \n if(mp.size() == pow(2,k))return true;\n return false;\n }\n};", ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string& s, int k){\n unordered_map<string, int> mp;\n int n = s.size(), total = pow(2,k);\n for (int i = 0; i < n-k+1; i++){\n mp[s.substr(i, k)]++;\n }\n return (mp.size() >= total) ? 1:0;\n }\n};", "memory"...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n if(s.length()<k)return false;\n unordered_map<string,bool>mp;\n for(int i=0;i<=s.length()-k;i++){\n mp[s.substr(i,k)]=true;\n }\n \n return mp.size()==pow(2,k);\n }\n};", "memory":...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n unordered_map<string,int> m;\n for(int i=0;(i+k)<=s.size();i++){\n m[s.substr(i,k)]++;\n if(m.size()==pow(2,k)) return true;\n }\n return false;\n }\n};", "memory": "139984" }
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n unordered_set<string>st;\n if (s.length() <= k) {\n return false;\n }\n for (int i = 0; i <= s.length() - k; i++)...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n\n bool hasAllCodes(string s, int k) {\n\n if (s.length() < k) return false;\n\n unordered_set<string> myset;\n int total_substrings = 1 << k; //pow(2, k);\n\n for (int i=0; i<= s.length()-k; i++){\n string substring = s.substr(i, k);\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n unordered_set<string> st;\n int n = s.size();\n for(int i=0;i<=n-k;i++){\n \n string str = s.substr(i,k);\n st.insert(str);\n \n }\n \n if(st.size()==pow(2,k)){\n...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n = s.size();\n if(k > n) return false;\n int noOfCodes = 1 << k; // 2^k binary codes\n unordered_set<string> st;\n for(int i=0;i<=n-k;i++){\n string temp = \"\";\n for(int j=0;...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n unordered_set<string> t;\n for(int i=0;i<s.size();i++)\n {\n string l=\"\";\n if(i+k<=s.size())\n {\n for(int j=i;j<i+k;j++)\n {\n l+=s[j];\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
2
{ "code": "class Solution {\npublic:\nvoid solve(vector<string> &arr,string &curr,int k){\n if(curr.size()==k){\n arr.push_back(curr);\n return;\n }\n curr.push_back('1');\n solve(arr,curr,k);\n curr.pop_back();\n curr.push_back('0');\n solve(arr,curr,k);\n curr.pop_back();\n\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n\n // void gen(int k, string str){\n // if(k==0){\n // st.insert(str);\n // return;\n // }\n\n // gen(k-1, str+'0');\n // gen(k-1, str+'1');\n // }\n bool hasAllCodes(string s, int k) {\n if (k > s.length())\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n\n int total = 1<<k;\n set<string> allSubstr;\n\n for(int i=0;i+k<=s.size();i++)\n {\n string str = s.substr(i,k);\n\n allSubstr.insert(str);\n\n if(allSubstr.size() == total)\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n= s.size();\n set<string> ss;\n for(int i=0;i<=n-k;i++){\n int j = k+i-1;\n string temp = s.substr(i,k);\n ss.insert(temp);\n }\n int total = pow(2,k);\n if(s...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n if (s.size() < k) return false;\n set<string>set;\n \n for(int i=0;i<=s.size()-k;i++)\n {\n string s1 = s.substr(i, k);\n set.insert(s1);\n }\n int p = 1 << k;\n ...