id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,445 | <p>You are given a string <code>s</code>. It may contain any number of <code>'*'</code> characters. Your task is to remove all <code>'*'</code> characters.</p>
<p>While there is a <code>'*'</code>, do the following operation:</p>
<ul>
<li>Delete the leftmost <code>'*'</code> and the <... | 3 | {
"code": "class Solution {\npublic:\n string clearStars(string s) {\n int n = s.length();\n\n int tillNowSmallest = 0;\n\n set<int> toRemove;\n\n for(int i=0;i<s.length();i++){\n if(s[tillNowSmallest]>=s[i] && s[i]!='*'){\n tillNowSmallest=i;\n }\n ... |
3,445 | <p>You are given a string <code>s</code>. It may contain any number of <code>'*'</code> characters. Your task is to remove all <code>'*'</code> characters.</p>
<p>While there is a <code>'*'</code>, do the following operation:</p>
<ul>
<li>Delete the leftmost <code>'*'</code> and the <... | 3 | {
"code": "class Solution {\npublic:\n string clearStars(string s) {\n int n = s.size();\n vector<vector<int>> adj(26); // To store the indices of each character ('a' to 'z')\n unordered_set<int> rem; // To store indices to be removed\n string ans = \"\"; // Result string\n pr... |
3,445 | <p>You are given a string <code>s</code>. It may contain any number of <code>'*'</code> characters. Your task is to remove all <code>'*'</code> characters.</p>
<p>While there is a <code>'*'</code>, do the following operation:</p>
<ul>
<li>Delete the leftmost <code>'*'</code> and the <... | 3 | {
"code": "class Solution {\npublic:\n string clearStars(string s) {\n int n = s.size();\n vector<vector<int>> adj(26); \n unordered_set<int> rem; \n string ans = \"\"; \n priority_queue<char, vector<char>, greater<char>> pq; \n for (int i = 0; i < n; i++) {\n ... |
3,445 | <p>You are given a string <code>s</code>. It may contain any number of <code>'*'</code> characters. Your task is to remove all <code>'*'</code> characters.</p>
<p>While there is a <code>'*'</code>, do the following operation:</p>
<ul>
<li>Delete the leftmost <code>'*'</code> and the <... | 3 | {
"code": "class Solution {\npublic:\n string clearStars(string s) {\n int n = s.size();\n vector<vector<int>> adj(26); \n unordered_set<int> rem; \n string ans = \"\"; \n priority_queue<char, vector<char>, greater<char>> pq; \n for (int i = 0; i < n; i++) {\n ... |
3,445 | <p>You are given a string <code>s</code>. It may contain any number of <code>'*'</code> characters. Your task is to remove all <code>'*'</code> characters.</p>
<p>While there is a <code>'*'</code>, do the following operation:</p>
<ul>
<li>Delete the leftmost <code>'*'</code> and the <... | 3 | {
"code": "class Solution {\npublic:\n string clearStars(string s) {\n auto compa = [](const auto& a, const auto& b){\n if(a.first == b.first) return a.second < b.second;\n return a.first > b.first;\n };\n\n priority_queue<pair<char,int>, vector<pair<char,int>>, decltype(... |
3,445 | <p>You are given a string <code>s</code>. It may contain any number of <code>'*'</code> characters. Your task is to remove all <code>'*'</code> characters.</p>
<p>While there is a <code>'*'</code>, do the following operation:</p>
<ul>
<li>Delete the leftmost <code>'*'</code> and the <... | 3 | {
"code": "class Solution {\npublic:\n class Pair {\n public:\n char ch; // The character\n int idx; // The index of the character in the string\n Pair(char ch, int idx) {\n this->ch = ch;\n this->idx = idx;\n }\n };\n\n struct Compare {\n bool op... |
3,445 | <p>You are given a string <code>s</code>. It may contain any number of <code>'*'</code> characters. Your task is to remove all <code>'*'</code> characters.</p>
<p>While there is a <code>'*'</code>, do the following operation:</p>
<ul>
<li>Delete the leftmost <code>'*'</code> and the <... | 3 | {
"code": "class Solution {\npublic:\n string clearStars(string s) {\n map<char,stack<int>>m;\n priority_queue<char,vector<char>,greater<char>>q;\n unordered_set<int> index;\n for(int i=0;i<s.length();i++){\n if(s[i]!='*'){\n if(m[s[i]].empty())\n ... |
3,445 | <p>You are given a string <code>s</code>. It may contain any number of <code>'*'</code> characters. Your task is to remove all <code>'*'</code> characters.</p>
<p>While there is a <code>'*'</code>, do the following operation:</p>
<ul>
<li>Delete the leftmost <code>'*'</code> and the <... | 3 | {
"code": "class Solution {\npublic:\n string clearStars(string s) {\n list<char> str;\n map<char, std::vector<list<char>::iterator>> posMap;\n\n for (const auto& c : s) {\n if (c == '*') {\n auto itr = posMap.begin();\n auto listItr = itr->second.back(... |
3,445 | <p>You are given a string <code>s</code>. It may contain any number of <code>'*'</code> characters. Your task is to remove all <code>'*'</code> characters.</p>
<p>While there is a <code>'*'</code>, do the following operation:</p>
<ul>
<li>Delete the leftmost <code>'*'</code> and the <... | 3 | {
"code": "class Solution {\npublic:\n string clearStars(string s) {\n list<char> str;\n map<char, std::vector<list<char>::iterator>> posMap;\n\n for (const auto& c : s) {\n if (c == '*') {\n auto itr = posMap.begin();\n auto listItr = itr->second.back(... |
3,445 | <p>You are given a string <code>s</code>. It may contain any number of <code>'*'</code> characters. Your task is to remove all <code>'*'</code> characters.</p>
<p>While there is a <code>'*'</code>, do the following operation:</p>
<ul>
<li>Delete the leftmost <code>'*'</code> and the <... | 3 | {
"code": "class Solution {\npublic:\n string clearStars(string s) {\n list<char> str;\n map<char, std::vector<list<char>::iterator>> posMap;\n\n for (const auto& c : s) {\n if (c == '*') {\n auto itr = posMap.begin();\n auto listItr = itr->second.back(... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 0 | {
"code": "class Solution {\npublic:\n int minimumDifference(std::vector<int>& array, int target) {\n int arrayLength = array.size();\n int startIndex = -1;\n int currentResult = std::abs(array[0] - target);\n int orAccumulator = 0;\n\n for (int endIndex = 0; endIndex < arrayLeng... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 0 | {
"code": "class Solution {\npublic:\n int minimumDifference(std::vector<int>& array, int target) {\n int arrayLength = array.size();\n int startIndex = -1;\n int currentResult = std::abs(array[0] - target);\n int orAccumulator = 0;\n\n for (int endIndex = 0; endIndex < arrayLeng... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 1 | {
"code": "#define ll long long \nclass Solution {\npublic:\n int minimumDifference(vector<int>& v, int k) {\n ll ans=INT_MAX;\n int i=0,j=0;\n map<ll,ll> m;\n ll sum=0;\n int n=v.size();\n while (j<v.size()){\n while (j<n&&sum<=k){\n sum|=v[j];\n... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 1 | {
"code": "class Solution {\npublic: \nint getsum(unordered_map<int , int>&c){\n int ans = 0 ;\n int bit = 0 ; \n while(bit<32){\n if(c[bit]>0){\n ans+=(1<<bit) ; \n } \n bit++ ; \n }\n return ans ; \n}\nvoid setbit(unordered_map<int , int>&c , int num , bool check){\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 1 | {
"code": "const int N = 1e5 + 1;\nint dp[N + 1][21]; \nclass Solution {\n \n int ans = INT_MAX;\n int n, k;\n int maxj;\n \n void dfs(int cur, int prev) {\n if(cur >= n) {\n return;\n }\n if(prev >= k) {\n return;\n }\n auto& v = dp[cur];\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 1 | {
"code": "#if 0\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int res = abs(nums[0] - k);\n int n = nums.size();\n\n for (int r = 0; r < n; ++r) {\n res = min(res, abs(nums[r] - k));\n for (int l = r - 1; l >= 0; --l) {\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 1 | {
"code": "class Solution {\n vector<int> seg;\n void build(int i,int l,int r,vector<int> &nums){\n if(l==r){\n seg[i] = nums[l];\n return;\n }\n int m = l+((r-l)>>1);\n build(i<<1,l,m,nums);\n build(i<<1|1,m+1,r,nums);\n seg[i] = seg[i<<1]|seg[i<<... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 1 | {
"code": "/*\nThe nature of Bitwise And is Decreasing\nSay V = bitwise And of subarray from L to R\nNow we need to find the minimum of abs(K - V)\nIf V < K = we try to increase V by shrinking our subarray\nIf V > K = we try to decrease V by expanding our subarray\nIf V = K = we found the minimum abs(K - V) . So retu... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "const int MX = 1e5;\nconst int LOG = 20;\n\nlong long m[MX][LOG];\n\nint query(int l, int r) {\n\tint len = r - l + 1;\n // cout << len << '\\n';\n\tint c = log2(len);\n\treturn m[l][c] | m[r - (1 << c) + 1][c]; // m[r - (1 << c) + 1][c]\n}\n\nint search2(int x, int left, int right) {\n int l = left,... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\n struct SparseTable {\n long long lg[100005], st[18][100005];\n void init(const vector<int>& a, int n) {\n for(int i = 1; i <= n; ++i) st[0][i] = a[i - 1];\n for(int j = 1; j <= 17; ++j) for(int i = 1; i <= n - (1 << j) + 1; ++i) st[j][i] = st[j - 1]... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "using int64 = long long;\n\n class segtree {\n public:\n struct node {\n // don't forget to set default value (used for leaves)\n // not necessarily neutral element!\n int64 sum = 0;\n int64 tag = 0;\n \n void apply(int l, int r, int64 v) {\n tag = ta... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#define ll long long\n#define vll vector<ll>\nclass Tree {\n public:\n ll n;\n vll t;\n \n Tree(ll n) {\n t.resize(4*n);\n this->n = n;\n }\n\n \n void build(vll &v, ll i, ll l, ll r) {\n if(l==r) t[i]=v[l];\n else {\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class SparseTable{\n int n, m;\n vector<vector<int>> dp;\npublic:\n SparseTable(vector<int> &a) {\n n = a.size();\n m = log2(n) + 1;\n dp.resize(m, vector<int>(n));\n for (int i = 0 ; i < n ; i++) dp[0][i] = a[i];\n for (int i = 1 ; i < m ; i++) {\n fo... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n const int inf=1e9+5;\n int minimumDifference(vector<int>& a, int k) {\n int n=a.size();\n int p=0,x=1;\n while(x<=n){\n x<<=1;\n p++;\n }\n p++;\n vector<vector<int>>t(p,vector<int>(n));\n for(int i=0;i... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class RMQ {\n static const int maxk = 16;\n int n;\n vector<vector<int>> rmq;\npublic:\n RMQ(vector<int> &vec) {\n n = vec.size();\n rmq = vector<vector<int>>(maxk+2, vector<int>(n+5, 0));\n for(int i = 0; i < n; ++i)\n rmq[0][i] = vec[i];\n for(int k = 1,... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\n/* Macros {{{ */\n/* A lot of this is from some of Benq's submissions\n [https://codeforces.com/profile/Benq]\n Ugly af to the eyes, but with vim fold its barable\n Hopefully c++20 concepts can make all this stuff must cleaner */\n\n/* Basics {{{ ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& arr, int k) {\n unordered_set<int>st;\n int n=arr.size();\n for(int i=0;i<n;i++)\n {\n int pre_or=0, curr_or=arr[i],j=i-1;\n st.insert(arr[i]);\n while(j>=0 && curr_or!=pre_or) \n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n set<int>s;\n for(int i = 0; i < nums.size(); i++) {\n s.insert(nums[i]);\n for(int j = i - 1; j >= 0; j--) {\n if((nums[i] | nums[j]) == nums[j]) break;\n num... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& arr, int k) {\n int n=arr.size();\n set<int>st;\n for (int i=0;i<arr.size();i++)\n {\n int curr=arr[i];\n int prev=0;\n st.insert(curr);\n int j=i-1;\n while ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int getsum(vector<int> num){\n int sum=0;\n for(int i=0;i<32;i++){\n if(num[i]>0){\n sum+=(1<<i);\n }\n }\n return sum;\n }\n int minimumDifference(vector<int>& v, int k) {\n int n=v.size();\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(0);\n int n=nums.size();\n vector<array<int,32>> freq(n);\n for(int k=0;k<n;k++){\n int v=nums[k];\n for(int i=0;i<32;i++){\n if(k>0)... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "static constexpr int M = 32;\n\nclass Solution {\npublic:\n int minimumDifference(vector<int>& a, int k) {\n\n cin.sync_with_stdio(false);\n cin.tie(nullptr);\n int n = a.size();\n vector<array<int, 32>> nx(n + 1);\n nx[n].fill(n);\n\n for (int i = n - 1; i >= 0... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n const int INF = INT_MAX / 2; \n int minimumDifference(vector<int>& nums, int k) {\n vector<array<int,32>> ones(nums.size()); \n for(int i = 0;i<nums.size();i++) {\n if(i > 0) [[likely]] {\n ones[i] = ones[i-1]; \n }\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n const int INF = INT_MAX / 2; \n int minimumDifference(vector<int>& nums, int k) {\n vector<array<int,32>> ones(nums.size()); \n for(int i = 0;i<nums.size();i++) {\n if(i > 0) [[likely]] {\n ones[i] = ones[i-1]; \n }\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int n=nums.size();\n vector<array<int,32>> freq(n);\n for(int k=0;k<n;k++){\n int v=nums[k];\n for(int i=0;i<32;i++){\n if(k>0)\n freq[k][i]=freq[k... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "static constexpr int M = 32;\n\nclass Solution {\npublic:\n int minimumDifference(vector<int>& a, int k) {\n int n = a.size();\n vector<array<int, 32>> nx(n + 1);\n nx[n].fill(n);\n\n for (int i = n - 1; i >= 0; i--)\n {\n nx[i] = nx[i + 1];\n\n f... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n // use the fact that or of subarray always inc with size\n int find_greatest(vector<vector<int>> &prefix, vector<int> &nums, int k , int idx , int n)\n {\n int ans = nums[idx];\n int low = 0 , high = idx;\n while(low <= high)\n {\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n // Initialize a vector to store the current set of ORs\n // Using a vector of integers since the number of unique ORs is small\n vector<int> prev_or_set;... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "struct tab{\n int lg = 17;\n vector<vector<int>> a;\n tab(vector<int>& aa){\n int n = aa.size();\n a.resize(n, vector<int>(lg));\n for (int i = 0; i < n;i ++)\n a[i][0] = aa[i];\n for (int j =0; j < lg - 1; j++)\n for (int i = 0; i + (1 << j) < n; ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n unordered_set<int> prev, curr;\n int ans = INT_MAX;\n\n for(int i: nums){\n curr = {i};\n for(int j: prev) curr.insert(i | j);\n prev = curr;\n for(int j: prev... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n unordered_set<int> prev, curr;\n int ans = INT_MAX;\n\n for(int i: nums){\n curr = {i};\n for(int j: prev) curr.insert(i | j);\n prev = curr;\n for(int j: prev... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "struct tab{\n int lg = 17;\n vector<vector<int>> a;\n tab(vector<int> aa){\n int n = aa.size();\n a.resize(n, vector<int>(lg));\n for (int i = 0; i < n;i ++)\n a[i][0] = aa[i];\n for (int j =0; j < lg - 1; j++)\n for (int i = 0; i + (1 << j) < n; i... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "struct tab{\n int lg = 20;\n vector<vector<int>> a;\n tab(vector<int> aa){\n int n = aa.size();\n a.resize(n, vector<int>(lg));\n for (int i = 0; i < n;i ++)\n a[i][0] = aa[i];\n for (int j =0; j < lg - 1; j++)\n for (int i = 0; i + (1 << j) < n; i... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) \n {\n vector<int> A(32,0);\n vector<string> B;\n int mini=INT_MAX,n=nums.size();\n\n for(int i=0;i<n;++i)\n B.push_back(bitset<32>(nums[i]).to_string());\n\n int currl=0,curr=0;\... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int res = abs(nums[0] - k);\n vector<int> arr = {nums[0]};\n for (int num: nums) {\n vector<int> tmp = {num};\n res = min(res, abs(num - k));\n for (int pre : arr) {\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Segtreenode {\npublic:\n int l, r;\n int val;\n Segtreenode *left, *right;\n Segtreenode(int l, int r) {\n this->l = l;\n this->r = r;\n left = NULL;\n right = NULL;\n }\n};\n\nclass SegTree {\npublic:\n S... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(0);\n cin.tie(0); cout.tie(0);\n unordered_set<int> set, temp;\n set.insert(nums[0]);\n int minimum = abs(nums[0]-k);\n for(int i=1; i<nums.size(); i++) {\n... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution \n{\npublic:\n int minimumDifference(vector<int>& nums, int k) \n {\n std::unordered_set<int> setNew, setOld;\n int n = nums.size(), result = INT_MAX;\n\n for (int i = 0; i < n; ++i)\n {\n setNew.clear();\n for (auto x : setOld)\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int ans = 0x7fffffff;\n unordered_set<int> ps, cs;\n for (int x : nums) {\n cs.insert(x);\n for (int v : ps) cs.insert(v | x);\n for (int v : cs) ans = min(ans, abs(k - v... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n vector<int> tmp;\n\n void up(int n, int ind){\n for(int i = 0; i < 32;i++){\n if((n&(1<<i)) != 0){\n tmp[i] = ind;\n }\n }\n }\n\n int minimumDifference(vector<int>& arr, int kk) { // arr = nums\n int target =... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#include <vector>\n#include <cmath>\n#include <algorithm>\n#include <limits>\n\nusing namespace std;\n\nclass Node {\npublic:\n int l, r, value;\n Node* left;\n Node* right;\n\n Node(const vector<int>& arr, int l, int r) : l(l), r(r), left(nullptr), right(nullptr) {\n if (l == r) {\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n unordered_set<int> st, st2;\n int ret = INT_MAX;\n for(int i=0;i<nums.size();i++){\n st.insert(0);\n for(int x : st){\n int orr = x | nums[i];\n ret = ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#include <vector>\n#include <set>\n#include <map>\n#include <queue>\n#include <stack>\n#include <unordered_set>\n#include <unordered_map>\n#include <bitset>\n#include <limits>\n#include <iostream> \n#include <iomanip> \n#include <string>\n#include <sstream> \n#include <algorithm>\n#include <numeric>\n#in... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<int>> pref(n, vector<int>(30, 0));\n for (int i = 0; i < 30; i++) {\n if ((1 << i) & nums[0]) {\n pref[0][i]++;\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& k, int m) {\n int n=k.size();\n vector<vector<int>> v(n+1,vector<int>(31));\n for(int i=0;i<n;i++){\n int x=k[i];\n for(int j=0;j<31;j++){\n v[i+1][j]=v[i][j];\n if(x%2... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& k, int m) {\n int n=k.size();\n vector<vector<int>> v(n+1,vector<int>(31));\n for(int i=0;i<n;i++){\n int x=k[i];\n for(int j=0;j<31;j++){\n v[i+1][j]=v[i][j];\n if(x%2... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& k, int m) {\n int n=k.size();\n vector<vector<int>> v(n+1,vector<int>(31));\n for(int i=0;i<n;i++){\n int x=k[i];\n for(int j=0;j<31;j++){\n v[i+1][j]=v[i][j];\n if(x%2... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int len = nums.size();\n vector<vector<int>> digitCnt(len + 1, vector<int>(32, 0));\n for (int i = 1; i <= len; ++i) {\n for (int j = 0; j <= 31; ++j) {\n if ((nums[i - 1] >> ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n \n vector<vector<int>> arr( nums.size(), vector<int>(32, 0) ); \n\n for( int j = 0; j < nums.size(); j++ )\n {\n for( int i = 0; i < 32; i++ )\n {\n if( nums[j... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n// using namespace __gnu_pbds;\n #define vb vector<bool>\n #define ff first\n #define ss second\n #define pb push_back\n #define gout(tno) cout << \"Case #\" << tno++ <<\": \"\n #define ld long double\n #define ll long lo... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int left = 0, n = nums.size(), right = 0, ans=INT_MAX;\n vector<int> cur(32);\n while(right<n){\n for(int i=0;i<32;i++){\n cur[i]+=(nums[right]&(1<<i))>0;\n }\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n // find all subarrays --> 30*N atmost 30 bits \n int n=nums.size(),ans=1e9;\n unordered_set<int>res,cur,cur1;\n\n for(auto i=0;i<n;i++){\n\n cur={nums[i]};\n \n fo... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n // OR more only makes it larger\n int mx = 0;\n for (auto& x: nums) mx |= x;\n if (mx <= k) return k - mx;\n int ans = mx - k;\n \n unordered_set<int> S{0};\n \n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int n = nums.size();\n // for every index store the last time 1 has occured\n vector<int> v(31,-1);\n int minn = 1e9;\n for(int i = 0; i < n; i++){\n int val = nums[i];\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> bitsPrefix;\n int minimumDifference(vector<int>& nums, int k) {\n int n = nums.size();\n bitsPrefix.resize(n+1, vector<int>(33, 0));\n\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < 32; j++) {\n bit... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) \n {\n unordered_set<int> prev, curr;\n set<int> res;\n for(auto i:nums)\n {\n curr={i};\n for(auto j:prev) curr.insert(j|i);\n for(auto j:curr) res.insert(j);\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) \n {\n unordered_set<int> prev, curr;\n set<int> res;\n for(auto i:nums)\n {\n curr={i};\n for(auto j:prev) curr.insert(j|i);\n for(auto j:curr) res.insert(j);\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(0);\n cin.tie(0); cout.tie(0);\n unordered_set<int> freqset, set, temp;\n set.insert(nums[0]), freqset.insert(nums[0]);\n for(int i=1; i<nums.size(); i++) {\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n unordered_set<int> freqset, set, temp;\n set.insert(nums[0]), freqset.insert(nums[0]);\n for(int i=1; i<nums.size(); i++) {\n temp.clear();\n for(auto ele: set) {\n t... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int n = nums.size();\n unordered_set<int> ans ; \n unordered_set<int> till_now;\n unordered_set<int> farji; \n for(int i = 0 ; i < n ; i++){\n farji.insert(nums[i]);\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n int minimumDifference(vector<int>& arr, int k) {\n int ans = INT_MAX;\n unordered_set<int> curr, prev, res;\n prev.insert(0);\n for(int i = 0; i < arr.size(); i++){\n int x = arr[i];\n for(auto y : prev){... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n int minimumDifference(vector<int>& arr, int k) {\n unordered_set<ll> curr, prev, res;\n prev.insert(0);\n for(int i = 0; i < arr.size(); i++){\n int x = arr[i];\n for(auto y : prev){\n curr.insert... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\nusing ll=long long;\ntypedef tree <pair<ll,ll>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\n/*\n order_of_key (k)\n find_by_order(k)\n*/\ntemplat... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\nusing ll=long long;\ntypedef tree <pair<ll,ll>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\n/*\n order_of_key (k)\n find_by_order(k)\n*/\ntemplat... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\nusing ll=long long;\ntypedef tree <pair<ll,ll>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\n/*\n order_of_key (k)\n find_by_order(k)\n*/\ntemplat... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\nusing ll=long long;\ntypedef tree <pair<ll,ll>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\n/*\n order_of_key (k)\n find_by_order(k)\n*/\ntemplat... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\n\n \nprivate:\n \n vector<int> convToBinary(int num) {\n \n vector<int> binaryRep(32, 0);\n \n for (int i=0; i<32; i++) {\n binaryRep[i] = num % 2;\n num = num / 2;\n }\n \n return binaryRep;\n \n }\... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n set<int> lasts;\n int res = INT_MAX;\n for (const int n : nums) {\n set<int> nexts;\n nexts.insert(n);\n for (const int last : lasts) {\n nexts.insert(n | ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "int v[35], d[35];\n\nclass Solution {\npublic:\n \n inline void cal(int a) {\n for(int i = 0; i < 31; i++) {\n if((1 << i) & a) {\n d[i] = 1;\n } else {\n d[i] = 0;\n }\n }\n }\n \n int minimumDifference(vector<int>... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n int minimumDifference(vector<int>& arr, int k) {\n unordered_set<ll> curr, prev, res;\n prev.insert((1LL<<31)-1);\n for(int i = 0; i < arr.size(); i++){\n int x = arr[i];\n for(auto y : prev){\n c... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int n = nums.size();\n set<int> dp[n];\n dp[0].insert(nums[0]);\n int res=abs(k-nums[0]);\n for(int i=1;i<n;i++){\n dp[i].insert(nums[i]);\n for(auto x:dp[i-1]){\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int n = nums.size();\n set<int> st[n + 1];\n for (int i = n - 1; i >= 0; i--) {\n st[i].insert(nums[i]);\n for (auto& sti : st[i + 1]) {\n st[i].insert(nums[i] | sti);\n }\n }\n int mn = IN... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& arr, int target) {\n int n=arr.size();\n set<int> st[n];\n st[n-1].insert(arr[n-1]);\n for(int i=n-2;i>=0;i--)\n {\n st[i].insert(arr[i]);\n for(auto it:st[i+1])\n {\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "#define ll long long\n\nclass Solution {\npublic:\n\n void add(int val, vector<int> &count)\n {\n for(int i = 0; i<32; i++)\n {\n if(((val>>i)&1)!=0)//if ith bit is zero\n {\n count[i]++;\n }\n }\n }\n\n void remove(int val, v... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& arr, int k) {\n int n=arr.size();\n set<int>st;\n int mini=INT_MAX;\n for (int i=0;i<arr.size();i++)\n {\n set<int>curr;\n for (auto it:st)\n {\n int x=it|arr... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 2 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n set<int> prev;\n int ans = INT_MAX;\n int n = nums.size();\n for(auto x:nums){\n set<int> next;\n for(auto y:prev){\n next.insert(x | y);\n }\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n long long n=nums.size(),ans=1e9;\n map<int,int>mp;\n for(int i=0;i<n;i++){\n map<int,int>mp1;\n for(auto [val,cnt]:mp){\n mp1[val|nums[i]]+=cnt;\n } \n mp1[nums[... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int n = nums.size();\n map<int, int> prev;\n long long res = 0;\n int ans=0, diff=INT_MAX;\n\n for(int i = 0; i <n; i++) {\n map<int, int> curr;\n\n for(auto &it: prev... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n // prev or cur store total unique value of and of subaaray possible starting from a index\n // particularly only log(nums[i]) values of and possible because value of and will change only when a bit turns into 0 from 1 in prev and\n int minimumDifference(vector<int>& num... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n // for closest &\n // prev or cur store total unique value of and of subaaray possible starting from a index\n // particularly only log(nums[i]) values of and possible because value of and will change only when a bit turns into 0 from 1 in prev and\n int minimumDiffe... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int ans=0,diff=1e9,n=nums.size();\n map<int,int>next_map;\n for(int i=n-1;i>=0;i--){\n int curEle=nums[i];\n map<int,int>cur_map;\n for(auto it : next_map){\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<int>> psum;\n for (int i=0; i<32; i++) {\n vector<int> ps = {0};\n for (int x : nums) {\n ps.push_back(ps.back() + ((x>>i)&1));\n... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<int>> psum;\n for (int i=0; i<32; i++) {\n vector<int> ps = {0};\n for (int x : nums) {\n ps.push_back(ps.back() + ((x>>i)&1));\n... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n #define ll long long\n int minimumDifference(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<ll>> dp(n, vector<ll>(32, 0));\n\n for (int i = 0; i < 32; i++) {\n if (nums[0] & (1 << i)) {\n dp[0][i]++;\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n #define ll long long\n int minimumDifference(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<ll>> dp(n, vector<ll>(32, 0));\n\n for (int i = 0; i < 32; i++) {\n if (nums[0] & (1 << i)) {\n dp[0][i]++;\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "// class Solution {\n// public:\n// int minimumDifference(vector<int>& nums, int k) {\n// int n = nums.size();\n// int min_diff = abs(k - nums[0]);\n// int or_value = 0;\n \n// for (int l = 0, r = 0; r < n; ++r) {\n// or_value |= nums[r];\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int ans = INT_MAX;\n unordered_set<int> curr_or_set;\n for (int num : nums) {\n unordered_set<int> next_or_set;\n next_or_set.insert(num);\n ans = min(ans, abs(k - num));... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution \n{\npublic:\n int minimumDifference(vector<int>& nums, int k) \n {\n std::unordered_set<int> new_set;\n int result = INT_MAX;\n\n for (auto x : nums)\n {\n std::unordered_set<int> old_set = std::move(new_set);\n new_set.clear();\n\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n // O(30*N) - Time complexity\n int minimumDifference(vector<int>&nums, int k){\n int n=nums.size();\n unordered_set<int>prev;\n int ans=INT_MAX;\n\n for(int i=0; i<n; i++){\n unordered_set<int>curr;\n for(auto it: prev){\n ... |
3,436 | <p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small... | 3 | {
"code": "class Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n unordered_set<int> ors;\n int best = INT_MAX;\n\n for(int i = 0; i<nums.size(); i++)\n {\n unordered_set<int> ors_ending_here;\n ors_ending_here.insert(nums[i]);\n\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.