id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
2
{ "code": "\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n unordered_map<int, int> cnt;\n long long res = 0;\n for (int n : nums) {\n unordered_map<int, int> cnt1;\n if ((k & n) == k) {\n cnt1[n] = 1;\n fo...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
2
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n unordered_map<int, int> cnt;\n long long res = 0;\n for (int n : nums) {\n unordered_map<int, int> cnt1;\n if ((k & n) == k) {\n cnt1[n] = 1;\n for ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
2
{ "code": "#pragma GCC optimize(\"O3, unroll-loops\")\n#pragma GCC target(\"avx2, bmi, bmi2, lzcnt, popcnt\")\n\nstatic auto _ = []() { \n cin.tie(nullptr) -> ios_base::sync_with_stdio(false); \n return nullptr; \n} ();\n\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
2
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans=0;\n map<int,long long> dp;\n for(int i=0;i<nums.size();i++)\n {\n map<int,long long> temp;\n for(auto it:dp)\n temp[it.first&nums[i]]+=it.sec...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
2
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n map<int,long long> freq;\n map<int,long long> dp;\n for(int i=0;i<nums.size();i++)\n {\n map<int,long long> temp;\n for(auto it:dp)\n temp[it.first&nums[i]]...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
2
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n int i,j;\n long long int res =0;\n map<long long, long long>mp;\n for(i=0;i<n;i++){\n map<long long,long long>temp;\n for(auto it:mp){\n ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
2
{ "code": "#define ll long long int\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n ll ans = 0;\n map<ll,ll> mp;\n ll n = nums.size();\n mp[nums[n-1]] = 1;\n if(nums[n-1]==k) ans++;\n // cout<<ans<<endl;\n for(ll i = n-2;i>=0;i--)...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
2
{ "code": "class Solution {\npublic:\n \n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n map<int,long long> mp;\n long long ans = 0;\n for(int i=n-1;i>=0;i--){\n map<int,long long> temp;\n for(auto v:mp){\n temp[v.fi...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
2
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n map<int, int> prev;\n long long res = 0;\n\n for(int i = 0; i <n; i++) {\n map<int, int> curr;\n\n for(auto &it: prev) {\n int andSum...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
2
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n long long ans = 0;\n map<int, int> prev;\n for (auto num: nums)\n {\n map<int, int> next;\n for (auto &[a, c] : prev){\n next[...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
2
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n map<int, int> prev;\n int n = nums.size();\n long long cnt = 0;\n for (int num : nums){\n map<int, int> cur;\n for (auto [key, v] : prev)\n cur[key & num] +...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n #define ll long long\n \n long long countSubarrays(vector<int>& a, int k) {\n int n=a.size();\n ll ans=0;\n map<ll,int> mp; \n for(int i=0;i<n;i++){\n map<ll,int> ms;\n mp[a[i]]++;\n for(auto &j:mp){\n ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n // int and_num(vector<int>&freq_bit,int len){\n // int ans=0;\n // for(int i=0;i<32;i++){\n // if(freq_bit[i]==len) ans+=(1<<i);\n // }\n // return ans;\n // }\n // long long count_sub(vector<int>&nums,int k){\n // long ans=...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "#define ll long long\n\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n map<int,int>prev_end;\n ll count=0;\n for(int i=n-1;i>=0;i--){\n map<int,int>new_end;\n // mp[x]=y stats that x is the `and...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n // map<int,int> prev_ends;\n // long long ans = 0;\n // int n = nums.size();\n // for(int i = n-1;i>=0;i--){\n // map<int,int> new_ends;\n // for(auto it : prev_ends)\n ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n map<int,int>mp;\n long long cnt = 0;\n for(int i=n-1;i>=0;i--){\n map<int,int>temp;\n for(auto v : mp){\n temp[(nums[i]&v.first)] = m...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n #define ll long long\n \n long long countSubarrays(vector<int>& nums, int k) {\n vector<vector<ll> > v11;\n vector<ll> v2;\n for(int i=0;i<nums.size();i++){\n if((nums[i]&k)!=k and v2.empty()==false){\n v11.push_back(v2);\n...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n unordered_map<int, long long> cnt;\n long long answer = 0;\n for (int i = 0; i < nums.size(); i++) {\n if ((k & nums[i]) == k) {\n unordered_map<int, long long> tmp;\n ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\n public:\n // Similar to 1521. Find a Value of a Mysterious Function Closest to Target\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n // the counter of all the values of subarrays that end in the previous\n // number\n unordered_map<int, int> p...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long result = 0;\n for (std::unordered_map<int, int> prev; const int num : nums)\n {\n std::unordered_map<int, int> curr{{num, 1}};\n for (const auto &[val, freq] : prev)\n ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n unordered_map<int, int> prev;\n for (auto num: nums) {\n unordered_map<int, int> curr;\n for (auto [key ,value] : prev) {\n curr[key & num]+=v...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n unordered_map<int,int> prev;\n const int n = nums.size();\n long long ans = 0;\n\n for (auto num : nums){\n unordered_map<int, int> curr;\n for (auto[k, v] : prev) curr[k&...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) \n {\n unordered_map<int,int>m;\n long long c = 0;\n for(auto val: nums)\n {\n unordered_map<int,int>mp;\n mp[val]=1;\n for(auto it=m.begin();it!=m.end();it++)\n...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n unordered_map<int, int> dict;\n\n long long cnt = 0;\n for (int i = 0; i < nums.size(); i++) {\n unordered_map<int, int> new_dict;\n new_dict[nums[i]] = 1;\n\n for (un...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n map<int,int> prev_ends;\n map<long long,long long> all;\n for(int i=n-1;i>=0;i--){\n map<int,int> new_ends;\n for(auto [x,y]: prev_ends){\n ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n unordered_map<int,int>mp;\n\n long long ans=0;\n\n for(int i=0;i<nums.size();i++){\n\n unordered_map<int,int>temp;\n\n for(auto x:mp){\n temp[x.first & nums[i]]+=x...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n=nums.size(),s=0;\n unordered_map<int,int> mp;\n long long res=0;\n for(int i:nums){\n unordered_map<int,int> tmp;\n tmp[i]=1;\n for(auto &[k,v]:mp){\n ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans=0;\n unordered_map<int,int>prev;\n for(auto i : nums){\n unordered_map<int,int>curr;\n for(auto a: prev){//O(N*32) AND NOT (N^2) AS ATMOST 32 ELES CAN BE THERE IN P...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& a, int k) {\n using ll = long long;\n ll n= a.size();\n map<ll,ll>prev,freq;\n ll ans=0;\n for(ll i=n-1;i>=0;i--){\n map<ll,ll>curr;\n for(auto [x,j]:prev){\n curr[x&...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n\n int query(int x, int y, vector<vector<int>> &mx, vector<int> &nums){\n if(x == y){\n return nums[x];\n }\n int mul = 1;\n int ct = 0;\n while(mul <= y - x){\n mul *= 2;\n ct++;\n }\n ct--;\n ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& arr, int k) {\n long long n = arr.size();\n \n map<long long,long long>prev_ends;\n map<long long,long long>freq;\n\n for(long long i = n - 1 ; i >= 0 ; i --){\n map<long long,long long>crr_en...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n int n = nums.size();\n vector<unordered_map<int, int>> mps(n, unordered_map<int, int>());\n mps[0].insert({nums[0], 1});\n if (nums[0] == k) {\n ans += 1;...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n int n = nums.size();\n vector<unordered_map<int, int>> mps(n, unordered_map<int, int>());\n mps[0].insert({nums[0], 1});\n if (nums[0] == k) {\n ans += 1;...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\ntypedef long long ll;\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n ll ans = 0;\n unordered_map<ll, ll>mp1;\n for(int i=0; i<n; i++) {\n unordered_map<ll, ll>mp2; \n if (nums[i]==k) ans++;\n ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n         long long ans = 0;\n         unordered_map<long long, long long> map1;\n         for (int i = 0; i < n; ++i) {\n             unordered_map<long long, l...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n        long long count = 0;\n        \n        unordered_map<long long, long long> mp1;\n\n        for (int i = 0; i < n; ++i) {\n            unordered_map<long long, long long> mp2; \n\n    ...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"Ofast\", \"inline\", \"unroll-loops\", \"no-stack-protector\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native\", \"f16c\")\n#define ll long long\n#define deb(x) cout << #...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "\n#include <bits/stdc++.h>\nusing namespace std;\n\n#ifdef DEBUG\n#include \"debug.h\"\n#else\n#define debug(...) 1\n#endif\n\nusing ll = long long;\nusing db = long double;\nusing VS = vector<string>;\nusing VLL = vector<ll>;\nusing VVLL = vector<VLL>;\nusing VVVLL = vector<VVLL>;\nusing PLL = pair<ll, ll...
3,466
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example...
3
{ "code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n unordered_map<int, long long> counts;\n\n for (auto num: nums) {\n unordered_map<int, long long> tmpCounts;\n for (auto &[value, count]: counts) {\n ...
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
0
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n string ans=\"\";\n for(int i=0;i<s.size();i++){\n ans+=s[(i+k)%s.size()];\n }\n return ans;\n }\n};", "memory": "8000" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
0
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n int n = s.length();\n string ans;\n\n for (int i = 0; i < s.size(); i++) {\n ans += s[(i + k) % n];\n }\n\n return ans;\n }\n};\n", "memory": "8100" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
0
{ "code": "class Solution {\npublic:\n std::string getEncryptedString(const std::string& s, int k) {\n std::string ans;\n for (int i = 0; i < s.size(); ++i) {\n ans.push_back(s[(i+k) % s.size()]);\n }\n return ans;\n }\n};", "memory": "8100" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
0
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n string output = \"\";\n for(int i = 0; i < s.size(); ++i){\n if(i + k >= s.size()){\n output += s[(i + k) % s.size()];\n }\n else{\n output += s[i + k];...
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
0
{ "code": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string getEncryptedString(string s, int k) {\n if (s.empty()) {\n return s;\n }\n \n string sb;\n int n = s.length();\n \n for (int i = 0; i < n; i++) {\n char or...
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
1
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n string ans=s;\n\n for(int i=0;i<s.size();i++){\n ans[i]=s[(i+k)% s.size()];\n }\n return ans;\n }\n};", "memory": "8300" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
1
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n \n int n = s.size();\n string result = \"\";\n\n for(int i=0; i<s.size(); i++)\n {\n int j = (i+k)%n;\n result.push_back(s[j]);\n }\n\n return result;\n }\...
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
2
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n string ans = \"\";\n int n = s.size();\n for (int i = 0; i < n; i++)\n ans += s[(i + k) % n];\n\n return ans;\n }\n};", "memory": "8400" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n int n=s.size();\n k%=n;\n s=s+s;\n return s.substr(k,n);\n }\n};", "memory": "8500" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n int len = s.size();\n if (k%len == 0)\n return s;\n else\n {\n int p = k%len;\n return s.substr(p) + s.substr(0, p);\n }\n }\n};", "memory": "8600" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n \n k %= (int)s.size();\n\n return s.substr(k) + s.substr(0, k);\n }\n};", "memory": "8700" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n \n k %= (int)s.size();\n\n return s.substr(k) + s.substr(0, k);\n }\n};", "memory": "8700" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\n public:\n string getEncryptedString(string s, int k) {\n k %= s.length();\n return s.substr(k) + s.substr(0, k);\n }\n};\n\n\n \n\n", "memory": "8800" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n stringstream ans;\n for (int i = 0; i < s.length(); ++i) {\n int index = i+k;\n while (index >= s.length()) {\n index = index - s.length();\n } \n ans ...
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n string st=\"\", str=\"\";\n // reverse(s.begin(), s.end()-k-1);\n int n=s.size();\n k=k%n;\n st=string(s.begin(), s.begin()+k);\n str=string(s.begin()+k, s.end());\n // cout<<st;\n...
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n int n = s.size();\n k = k % n;\n if(k == 0) return s;\n\n string t = s;\n string x = s;\n for(int i=0; i<t.size(); i++){\n swap(t[i],x[k]);\n k++;\n x = s...
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n int n = s.size();\n k %= n;\n queue<char> q;\n \n for(auto &c: s){\n q.push(c);\n }\n string remain = \"\";\n string res = \"\";\n while(!q.empty()){\n ...
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n int n = s.size(); \n string ans = \"\"; \n for(int i = 0; i<n; i++){\n ans = ans + (s[(i + k) % n]); \n }\n return ans; \n }\n};", "memory": "9600" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\n string str;\n int n=s.size();\n for(int i=0;i<n;i++){\n str=str+s[(i+k)%n];\n }\n return str;\n }\n};", "memory": "9700" }
3,468
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> <ul> <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li...
3
{ "code": "class Solution {\npublic:\n string getEncryptedString(string s, int k) {\nstring ans;\n int n=s.size();\n for(int i=0;i<n;i++){\n ans = ans + s[(i + k) % n];\n }\n return ans;\n }\n};", "memory": "9800" }
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
0
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n vector<string> res { \"0\", \"1\" };\n while (--n) {\n for (size_t i = res.size(); i --> 0;) {\n if (res[i].back() == '0') res[i].push_back('1');\n else {\n res.pu...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
0
{ "code": "class Solution {\npublic:\n\n string val2s(int val, int n)\n {\n string s;\n for (int i=0; i<n; i++)\n if (val & (1 << i))\n s.push_back('1');\n else\n s.push_back('0');\n return s;\n }\n\n bool check(int val, int n)\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
0
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n if(n == 1){\n return {\"0\",\"1\"};\n }\n vector<string> v;\n vector<string> prev = validStrings(n - 1);\n\n for(string& str : prev){\n if(str.back() == '1'){\n v.pu...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
0
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n vector<string> res = {\"1\", \"0\"};\n for(int i=1; i < n;i++){\n vector<string> tmp;\n for(string w : res){\n tmp.push_back(w + '1');\n if(w.back() == '1')\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
1
{ "code": " class Solution {\n public:\n void returnsString(string cur, int n, vector<string> &all) {\n\n while (cur.length() < n) {\n if (cur[cur.length()-1] == '0') {\n all.push_back(cur + '1');\n }\n else {\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
1
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n vector<string> ans;\n function<void(string)> backtrack = [&](string s) {\n if(s.size() == n) {\n ans.push_back(s);\n return;\n }\n if(s.size() == 0) {\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
1
{ "code": "class Solution {\npublic:\n void h(int n,vector<string>&ans,string temp)\n {\n if(n==0)\n {\n ans.push_back(temp);\n return ;\n }\n if(n==1)\n {\n h(n-1,ans,temp+\"0\");\n h(n-1,ans,temp+\"1\");\n return ;\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
1
{ "code": "int a[20];\nclass Solution {\npublic:\n void Try(int i, int n, vector<string>& ret){\n for(int j = 0; j <= 1; j++){\n a[i] = j; \n if ( i == n - 1){\n int check = 1; \n for(int t = 0; t < n - 1; t++) if ( a[t] != 1 && a[t+1] != 1) check = 0; \n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
2
{ "code": "class Solution {\npublic:\n void recur(int n,vector<string> &ans, string s){\n if(s.length() == n){\n ans.push_back(s);\n return;\n }\n s+='1';\n recur(n,ans,s);\n s.pop_back();\n if(s.back() != '0')recur(n,ans,s+'0');\n }\n vector<st...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
2
{ "code": "#include <vector>\n#include <string>\n\nclass Solution {\npublic:\n std::vector<std::string> ans;\n\n void generateString(int i,string s,int n){\n \n if(i == n){\n ans.push_back(s);\n return;\n }\n \n if(s[i-1] == '0'){\n s[i] ='1';\...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> ans;\n void recurse(int i, int n, string temp)\n {\n if(i==n)\n {\n ans.push_back(temp);\n return;\n }\n\n if(i>0 and temp[i-1]=='0')\n {\n temp.push_back('1');\n recurse(i+1, ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n\n vector<string> cRet;\n void f(string x,int n)\n {\n if(x.size()>n)\n return;\n if(x.size()==n)\n cRet.push_back(x);\n \n f(x+'1',n);\n\n if(x[x.size()-1]!='0')\n {\n f(x+'0',n);\n }\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> res;\n void addzero(string s, int n){\n if(s.length()==n){\n res.push_back(s);\n return;\n }\n if(s.length()==0 || s[s.length()-1]!='0'){\n string s1=s+'0';\n addzero(s1, n);\n if(s1...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\nset<string> st;\nvoid f(char c,string s,int n){\n if(s.size() ==n) { st.insert(s); return ; }\n if(c=='0')\n f('1',s+'1',n);\n else{\n f('0',s+'0',n);\n f('1',s+'1',n);\n }\n}\n vector<string> validStrings(int n) {\n vector<string> ans;\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n bool isValid(const string&s, int n){\n for(int i = 21 - n; i < s.size(); i++){\n if(s[i] == '0' && s[i-1] == '0') return false;\n }\n\n return true;\n }\n vector<string> validStrings(int n) {\n vector<string> res;\n\n for(in...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n vector<string> ans;\n set<string> st;\n for(int i=0;i<(1<<n);i++){\n string t=\"\";\n for(int j=0;j<n;j++) t+='1';\n for(int j=0;j<n;j++){\n if(i & (1<<j)){\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n void solve(int i,string curr,string tar,vector<string> &ans,int n)\n {\n if(curr.length()==n)\n ans.push_back(curr);\n\n if(curr==tar || i>n)\n return;\n\n if(i==0 || curr[i-1]=='1')\n {\n solve(i+1,curr+\"1\",tar,ans,n)...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n \n void buildValidSubstr(string s, vector<string>& ans, int n){\n int m = s.size();\n if(m == n) {\n ans.push_back(s);\n return;\n }\n if(m == 0 || s[m - 1] == '1') buildValidSubstr(s + \"0\", ans, n);\n buildValidSu...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n set<string> ans;\n string op = \"\";\n solve(op, n, ans);\n vector<string>res(ans.begin(),ans.end());\n return res;\n }\n\n void solve(string op, int n, set<string>& ans) {\n if (n == 0) {\...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n\n vector<string> f(int n,bool choice){\n if(n==1){\n if(choice)return {\"1\",\"0\"};\n return {\"1\"};\n }\n vector<string> res;\n auto a = f(n-1,1);//put 1 \n if(choice){\n auto b = f(n-1,0); //put 0 \n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n vector<string> validStrings(int n) {\n vector<string>ans;\n int start=pow(2,n-2)-1;\n int end=pow(2,n)-1;\n const int N=n;\n for(int i=start;i<=end;i++)\n {\n bitset<18>V(i);\n string X=\...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n return helper(\"\", n);\n }\n\n vector<string> helper(string pre, int n) {\n vector<string> res;\n if (n == 0) {\n res.push_back(pre);\n return res;\n }\n if (pre.empty() || ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> calc(int prev, int n) {\n if (n == 0) return {\"\"};\n vector<string> result;\n if (prev) {\n auto first = calc(0, n - 1);\n for (auto x: first) {\n result.push_back(\"0\" + x);\n }\n }...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n bool check(string s)\n {\n for(int i=0;i<s.size()-1;i++)\n {\n if(s[i]=='0' && s[i+1]=='0')\n return false;\n }\n return true;\n }\n vector<string> validStrings(int n) {\n \n vector<string >a;\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic: \n\n bool check(string s){\n for(int i=0;i<s.length()-1;i++){\n if(s[i]=='0'&&s[i+1]=='0') return false;\n }\n return true;\n }\n vector<string> validStrings(int n) {\n vector<string>vec;\n for(int i=0;i<(1<<n);i++){\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> helper(int n, int i, int zeros, string temp) {\n // Base Case: If index `i` reaches `n`, return the current string as a valid result\n if (i >= n) {\n return {temp};\n }\n\n vector<string> a;\n \n // Case whe...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> helper(int n, int i, int zeros, string temp) {\n // Base Case: If index `i` reaches `n`, return the current string as a valid result\n if (i >= n) {\n return {temp};\n }\n\n vector<string> a;\n \n // Case whe...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n return helper(\"\", n);\n }\n\n vector<string> helper(string pre, int n) {\n vector<string> res;\n if (n == 0) {\n res.push_back(pre);\n return res;\n }\n if (pre.empty() || ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n if(n == 1){\n return vector<string> {\"0\", \"1\"};\n }\n return generate(n, \"\");\n }\n vector<string> generate(int n, string s){\n if(n == 0){\n bool valid = false;\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n vector<string> result;\n int temp = pow(2, n); // Total number of binary strings of length n\n \n for (int i = 0; i < temp; i++) { // Generate all binary strings from 0 to 2^n - 1\n int num = i; ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n vector<string> result;\n int temp = pow(2, n); // Total number of binary strings of length n\n \n for (int i = 0; i < temp; i++) { // Generate all binary strings from 0 to 2^n - 1\n int num = i; ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n // Function to check if a binary string is valid (no adjacent zeros)\n bool isValid(const string& s) {\n for (int i = 0; i < s.length() - 1; ++i) {\n if (s[i] == '0' && s[i + 1] == '0') {\n return false;\n }\n }\n r...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n bool isValid(const string& s) {\n for (int i = 0; i < s.length() - 1; ++i) {\n if (s[i] == '0' && s[i + 1] == '0') {\n return false;\n }\n }\n return true;\n }\n\n vector<string> generateAllBinaryStrings(int n) {...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n bool isValid(const string& s) {\n for (int i = 0; i < s.length() - 1; ++i) {\n if (s[i] == '0' && s[i + 1] == '0') {\n return false;\n }\n }\n return true;\n }\n\n vector<string> generateAllBinaryStrings(int n) {...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n bool check(string &s)\n {\n for(int i=0;i<s.length()-1;i++)\n {\n if(!(s[i]-'0') && !(s[i+1]-'0'))\n {\n return false;\n }\n }\n return true;\n }\n void solve(int n, vector<string> &ans, stri...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n bool check(string &s)\n {\n for(int i=0;i<s.length()-1;i++)\n {\n if(!(s[i]-'0') && !(s[i+1]-'0'))\n {\n return false;\n }\n }\n return true;\n }\n void solve(int n, vector<string> &ans, stri...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n bool isvalid(string s){\n int n = s.length();\n for(int i = 0 ; i < n-1 ; i++){\n if(s[i] == '0' and s[i+1] == '0') return false;\n }\n return true;\n }\n vector<string> validStrings(int n) {\n vector<string> p ;\n in...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "\nclass Solution {\n\npublic:\n\n bool check(string s)\n {\n \n if(s.size()<2)\n {\n return true;\n }\n \n cout<<s<<endl;\n\n for(int i=0;i<s.size()-1;i++)\n {\n if(s[i]!='1' && s[i+1]!='1')\n {\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\nprivate:\n bool isValid(string s){\n for (int i = 1; i < s.size(); i++){\n if (s[i] == '0' && s[i - 1] == '0') return false;\n }\n return true;\n }\n\n bool incBin(string &s){\n int t = 1;\n for (int i = s.size() - 1; i >= 0; i--){\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\nprivate:\n bool isValid(string s){\n for (int i = 1; i < s.size(); i++){\n if (s[i] == '0' && s[i - 1] == '0') return false;\n }\n return true;\n }\n\n bool incBin(string &s){\n int t = 1;\n for (int i = s.size() - 1; i >= 0; i--){\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n set<string> f(int ind, string s, bool flag) {\n set<string> ans;\n\n // Base case: when ind becomes negative, add the current string to the results\n if (ind < 0) {\n ans.insert(s); // Use insert with set\n return ans;\n }\n\n...