id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "class Solution {\npublic:\n typedef bitset<129> bt; // bitset of size 129 (0 to 128)\n \n int maxValue(vector<int>& nums, int d) {\n int n = nums.size();\n \n // Create the dp array\n vector<vector<bt>> dp1(n+1, vector<bt>(d+1));\n vector<vector<bt>> dp2(n+2, ve...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "class Solution {\npublic:\n\n int cnt_set(int x){\n int ans = 0;\n while (x){\n ans += x&1;\n x >>= 1;\n }\n return ans;\n }\n\n int getMinDx(vector<int>& nums, int k, int x){\n int n = nums.size();\n vector<int> mark(n,0), have;\n\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n vector<unordered_set<int>> left(n),right(n),dp(k+1),dp2(k+1);\n int count=0;\n for(int i=0;i<n-k;i++){\n count++;\n for(int j=min(count,k);j>=2;j--){\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n // left_dp[i][mask] -> have OR mask of length k ending <= i\n // while running through, maintain dp[length][mask]\n // dp[L][mask] = have subsequence of length L, with OR mask, up un...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "class Solution {\n int findMaximumXOR(unordered_set<int>& a, unordered_set<int>& b) {\n int res = 0;\n for(auto& x : a) for(auto& y : b) res = max(res, x ^ y);\n return res;\n }\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size(), ma = 1<<7;\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "/////////////////////////////// Preface\n// utility functions\nusing ll = long long;\nusing ld = long double;\nusing ull = unsigned long long;\n\n// typedef\ntypedef pair<int, int> pii;\ntypedef pair<ll, ll> pll;\ntypedef tuple<int, int, int> ti3;\ntypedef tuple<int, int, int, int> ti4;\ntypedef tuple<int,...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "#include <vector>\n#include <set>\n#include <unordered_set>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n // Use vector of sets to store intermediate OR values for left and right parts\n vector<unordered_set<int>> va...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int val = 0;\n for( int num : nums ) {\n val |= num;\n }\n\n //cout<<val<<\"\\n\";\n reverse( nums.begin(), nums.end() );\n vector<int> nums2 = nums;\n reverse( nums.begin()...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int val = 0;\n for( int num : nums ) {\n val |= num;\n }\n\n //cout<<val<<\"\\n\";\n reverse( nums.begin(), nums.end() );\n vector<int> nums2 = nums;\n reverse( nums.begin()...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& as, int k) {\n const auto n = int(as.size());\n constexpr int A = 7;\n using T = array<bool, 1 << A>;\n vector sf(n+1, vector<T>(k + 1));\n for (int i = 0; i < n; ++i) {\n for (int len = 0; len <= k; ++len) {\n sf[i][len].fil...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = (int) nums.size();\n int N = 1 << 7;\n\n vector<vector<vector<bool>>> pre(n, vector<vector<bool>>(k + 1, vector<bool>(N, false)));\n int res = 0;\n\n for (int i = 0; i < n; i++) {\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "class Solution {\npublic:\n vector<vector<vector<bool>>> GetCandidates(const vector<int>& nums, int k, int maxval) {\n int n=nums.size();\n vector<vector<vector<bool>>> dp(n+1);\n for(int pos=0;pos<=n;pos++) {\n // using the first pos elements -> 0,..min(pos,k)\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "int pre[401][201][128];\nint suf[401][201][128];\nint first[128], last[128];\n\nclass Solution {\n void dfs_pre(vector<int>& nums, int i, int k, int mask) {\n if(k == 0) {\n first[mask] = min(first[mask], i - 1);\n } else if(i + k < nums.size() && pre[i][k][mask] == -1) {\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "int pre[401][201][128];\nint suf[401][201][128];\n\nclass Solution {\n void dfs_pre(vector<int>& nums, int i, int k, int mask) {\n if (i > nums.size() || k < 0)\n return;\n if (pre[i][k][mask] != -1)\n return;\n pre[i][k][mask] = 1;\n dfs_pre(nums, i + 1...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "int dpl[410][210][128], dpr[410][210][128];\n\nclass Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n memset(dpl, 0, sizeof(dpl));\n memset(dpr, 0, sizeof(dpr));\n for(int i = 0; i <= n; i++)\n dpr[i][0][0] = dpl[i][0][0] = 1;...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "void build_pre(vector<int> &a, int i, int k, int mask, vector<vector<vector<bool>>> &dp) {\n if(i == a.size())\n return;\n\n if(k < 0)\n return;\n\n if(dp[i][k][mask])\n return;\n\n dp[i][k][mask] = 1;\n if(k > 0) {\n dp[i][k - 1][mask | a[i]] = 1;\n build_...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int f[405][205][128], g[405][205][128], a[405], n;\n int maxValue(vector<int>& nums, int k) {\n n = nums.size();\n for(int i = 1; i <= n; ++i) a[i] = nums[i - 1];\n f[0][0][0] = g[n + 1][0][0] = 1;\n for(int i = 1; i <= n; ++i)\n for(...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int dp[401][205][130],dp1[401][205][130];\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n for(int i = 0; i < n; i++) {\n for(int j = 0; j <= k; j++) {\n for(int jj = 0; jj <= 128; jj++) {\n if(j...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\n public:\n int maxValue(vector<int>& nums, int k) {\n int ans = 0;\n const vector<vector<vector<bool>>> left = getPossibleORs(nums, k);\n vector<vector<vector<bool>>> right =\n getPossibleORs({nums.rbegin(), nums.rend()}, k);\n ranges::reverse(right);\n\n for (int i...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n static const int M = 1 << 7;\n int pref[455][201][M];\n int suff[455][201][M];\n\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n \n for (int i = 0; i < n; i++) {\n for (int j = 0; j <= k; j++) for (int l = 0; l < M;...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int LIM = 129;\n \n int maxValue(vector<int>& nums, int k) {\n \n int n = nums.size();\n \n vector<vector<vector<bool>>> vis1(n, vector<vector<bool>>(k+1, vector<bool>(LIM, false)));\n vector<vector<vector<bool>>> vis2(n, vector<vector...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int LIM = 129;\n \n int maxValue(vector<int>& nums, int k) {\n \n int n = nums.size();\n \n vector<vector<vector<bool>>> vis1(n, vector<vector<bool>>(k+1, vector<bool>(LIM, false)));\n vector<vector<vector<bool>>> vis2(n, vector<vector...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "struct Counter {\n int bit, target, count, k;\n unordered_set<int> vals;\n Counter(int x, int k): bit(0), target(x), count(0), k(k) {}\n void add(int x) {\n if((target & x) != x) return;\n bit |= x;\n vals.insert(x);\n count++;\n }\n bool ok() {\n if(bit...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "struct node {\n node* c[2];\n node() {c[0]=nullptr; c[1]=nullptr;}\n};\nclass Solution {\npublic:\n const static int MAX=257;\n bool V[402][202][MAX];\n vector<vector<int>> O[2];\n int C[2][MAX];\n bool rNotEmpty(node* r) {\n return (r->c[0]!=nullptr||r->c[1]!=nullptr);\n }\n...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\nvector<int> v[401];\nvector<int> v2[401];\nint dp[401][201][128];\nint dp2[401][201][128];\nvoid func(int ind,int count,int sum,vector<int> &nums,int k){\n\n if(ind==nums.size())return;\n if(dp[ind][count][sum]==1)return;\n dp[ind][count][sum]=1;\n if(count==k)v[ind][...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#include <ranges>\nnamespace R = ranges;\nnamespace V = views;\nclass Solution {\npublic:\n int maxValue(vector<int> &nums, int k) {\n constexpr int value_upper_bound = 1 << 7;\n const int n = nums.size();\n vector lv(n, vector<array<bool, value_upper_bound>>(k + 1));\n vector rv(n, vector<arr...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<unordered_set<int> > > fortab(\n 2, vector<unordered_set<int> >(\n n, unordered_set<int>()));\n vector<vector<unordered_set<int> > > bactab(\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "// DEBUGGING TEMPLATE\n#define sim template < class c\n#define ris return * this\n#define dor > debug & operator <<\n#define eni(x) sim > typename \\\nenable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {\nsim > struct rge { c b, e; };\nsim > rge<c> range(c i, c j) { return rge<c>{i, j}; }\nsim >...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n vector<bitset<201>> pre(128,0);\n vector<int> pre2(128,-1);\n int n = nums.size();\n // bitse\n for(int i=0;i<n;i++){\n vector<bitset<201>> pree=pre;\n for(int j=1;j<128;j++){\...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n std::vector<std::vector<std::vector<bool> > > visited;\n std::vector<std::vector<std::vector<bool> > > lefts;\n std::vector<std::vector<std::vector<bool> > > rights;\n vector<int> nums;\n int k;\n\n void infect1(int i, int j, int mask) {\n if (i >= lefts...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "struct Counter {\n int bit, target, count, k;\n unordered_set<int> vals;\n Counter(int x, int k): bit(0), target(x), count(0), k(k) {}\n void add(int x) {\n if((target & x) != x) return;\n bit |= x;\n vals.insert(x);\n count++;\n }\n bool ok() {\n if(bit...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "int dp[405][128][405];\nint dp_rev[405][128][405];\nclass Solution {\npublic:\n \n \n int maxValue(vector<int>& a, int k) {\n int n = a.size();\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < 128; j++) {\n for (int s = 0; s <= n; s++) {\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "int pre[402][202][1 << 8];\nint suf[402][202][1 << 8];\nclass Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n int mx = 0;\n for (int x : nums) {\n mx = max(mx, x);\n }\n mx *= 2;\n for (int i = 0; i <= n + 1; i+...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n const int n = nums.size();\n vector<vector<vector<char>>> left(n, vector<vector<char>>(k + 1, vector<char>(128, 0)));\n auto right = left;\n preprocess(nums, k, left);\n reverse(begin(nums), end(num...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<vector<unsigned char>>> pd(n+1, vector<vector<unsigned char>>(k+1, vector<unsigned char>(128)));\n vector<vector<vector<unsigned char>>> sd(n+1, vector<vector<unsigned char>>(...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "\nclass Solution {\n public:\n int maxValue(vector<int> &nums, int k) {\n int n = (int)nums.size();\n\n vector<vector<vector<char>>> dp(n + 1, vector<vector<char>>(k + 1, vector<char>(1 << 7)));\n\n dp[0][0][0] = 1;\n\n for (int i = 0; i < n; i++) {\n for (int j ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> left(1<<7,n), right(1<<7,-n);\n vector<vector<vector<vector<bool>>>> dp(2,vector<vector<vector<bool>>>(n,vector<vector<bool>>(n/2,vector<bool>(1<<7))));\n function<void(i...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> left(1<<7,n), right(1<<7,-n);\n vector<vector<vector<vector<bool>>>> dp(2,vector<vector<vector<bool>>>(n,vector<vector<bool>>(n/2,vector<bool>(1<<7))));\n function<void(i...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n=nums.size(),ans=0;\n vector<vector<vector<int>>> suff(n, vector<vector<int>>(k+1, vector<int>(1<<7)));\n vector<vector<int>> upto(k+1, vector<int>(1<<7));\n suff[n-1][1][nums[n-1]]=1;\n for(in...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#define ll long long\nll dp1[401][401][129];\nll dp2[401][401][129];\nclass Solution {\npublic:\n void help(ll i, ll j, ll k,vector<int>& nums){\n ll n=nums.size();\n //cout<<i<<\" \"<<j<<\" \"<<k<<endl;\n if(dp1[i][j][k]!=0){\n return ;\n }else{\n dp1[i...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n vector<vector<pair<int,int>>> prefix = vector<vector<pair<int,int>>>(401,vector<pair<int,int>>(129,{1e9,0})) ;\n vector<vector<pair<int,int>>> suffix = vector<vector<pair<int,int>>>(401,vector<pair<int,int>>(129,{1e9,0})) ;\n\n void solve(vector<int> &nums){\n\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n\n int maxValue(vector<int>& nums, int k) {\n int n=nums.size();\n int ans=0;\n vector<vector<int>>left_mi(401,vector<int>(128,INT_MAX));\n vector<vector<int>>left_ma(401,vector<int>(128,0));\n for(int i=0;i<nums.size();i++){\n left_mi[i][0]=...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#define pii pair<int, int>\n#define F first\n#define S second\n\nclass Solution {\npublic:\n vector<vector<pii>> prefix;\n vector<vector<pii>> suffix;\n void Compute(vector<int>& arr) {\n int n = arr.size();\n \n prefix[0][arr[0]] = {1, 1};\n for (int j = 1; j < n; j +...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#define pii pair<int, int>\n#define F first\n#define S second\n\nclass Solution {\npublic:\n vector<vector<pii>> prefix;\n vector<vector<pii>> suffix;\n void Compute(vector<int>& arr) {\n int n = arr.size();\n \n prefix[0][arr[0]] = {1, 1};\n for (int j = 1; j < n; j +...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#define pii pair<int, int>\n#define F first\n#define S second\n\n\nclass Solution {\npublic:\n vector<vector<pii>> prefix;\n vector<vector<pii>> suffix;\n\n void compute(vector<int>& arr)\n {\n int n= arr.size();\n prefix[0][arr[0]] = {1,1};\n for(int i = 1;i<n;i++)\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#define pii pair<int, int>\n#define F first\n#define S second\n\nvector<vector<pii>> prefix(401, vector<pii>(128, {1e9, 0}));\nvector<vector<pii>> suffix(401, vector<pii>(128, {1e9, 0}));\n\nclass Solution {\n \n void Compute (const vector<int>& arr) {\n int n = arr.size();\n \n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#define pii pair<int,int>\n#define f first\n#define s second\n\n// f denotes minimum cost \n// s denotes maximum cost\n\nvector<vector<pii>> prefix(401, vector<pii>(128, {1e9, 0}));\nvector<vector<pii>> suffix(401, vector<pii>(128, {1e9, 0}));\n\nclass Solution {\nprivate:\n void Compute(vector<int>& ar...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#include <vector>\n#include <algorithm>\nusing namespace std;\n\n\nclass Solution {\npublic:\n int maxValue(vector<int>& arr, int k) {\n int g = 128; // Target OR value\n int n = arr.size();\n \n // DP tables for original and reversed arrays\n const int MAX_OR = 128;\n...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#include <vector>\n#include <algorithm>\nusing namespace std;\n\n\nclass Solution {\npublic:\n int maxValue(vector<int>& arr, int k) {\n int g = 128; // Target OR value\n int n = arr.size();\n \n // DP tables for original and reversed arrays\n const int MAX_OR = 128;\n...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#include <vector>\n#include <algorithm>\nusing namespace std;\n\n\nclass Solution {\npublic:\n int maxValue(vector<int>& arr, int k) {\n int g = 128; // Target OR value\n int n = arr.size();\n \n // DP tables for original and reversed arrays\n const int MAX_OR = 128;\n...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n\n auto getPre(vector<int> &nums, int k) {\n const int n = nums.size();\n vector<vector<vector<bool> > > dp(n, vector<vector<bool> >(1 << 7, vector<bool>(k + 1, 0)));\n vector<vector<int> > res(n, vector<int>(1 << 7, 0));\n dp[0][nums[0]][1] = 1;\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#ifdef LOCAL\n #include \"../../../lib/bits.h\"\n #include \"../../../lib/leetcode.h\"\n #include \"../../../lib/debug.h\"\n#else\n #define debug(...) 1\n#endif\n\nusing ll = long long;\n\ntemplate <typename T>\nstruct PairHash {\n size_t operator() (const pair<T, T>& v) const {\n return hash<size_...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#ifdef LOCAL\n #include \"../../../lib/bits.h\"\n #include \"../../../lib/leetcode.h\"\n #include \"../../../lib/debug.h\"\n#else\n #define debug(...) 1\n#endif\n\nusing ll = long long;\n\ntemplate <typename T>\nstruct PairHash {\n size_t operator() (const pair<T, T>& v) const {\n return hash<size_...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#ifdef LOCAL\n #include \"../../../lib/bits.h\"\n #include \"../../../lib/leetcode.h\"\n #include \"../../../lib/debug.h\"\n#else\n #define debug(...) 1\n#endif\n\nusing ll = long long;\n\ntemplate <typename T>\nstruct PairHash {\n size_t operator() (const pair<T, T>& v) const {\n return hash<size_...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#ifdef LOCAL\n #include \"../../../lib/bits.h\"\n #include \"../../../lib/leetcode.h\"\n #include \"../../../lib/debug.h\"\n#else\n #define debug(...) 1\n#endif\n\nusing ll = long long;\n\ntemplate <typename T>\nstruct PairHash {\n size_t operator() (const pair<T, T>& v) const {\n return hash<size_...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#ifdef LOCAL\n #include \"../../../lib/bits.h\"\n #include \"../../../lib/leetcode.h\"\n #include \"../../../lib/debug.h\"\n#else\n #define debug(...) 1\n#endif\n\nusing ll = long long;\n\ntemplate <typename T>\nstruct PairHash {\n size_t operator() (const pair<T, T>& v) const {\n return hash<size_...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#ifdef LOCAL\n #include \"../../../lib/bits.h\"\n #include \"../../../lib/leetcode.h\"\n #include \"../../../lib/debug.h\"\n#else\n #define debug(...) 1\n#endif\n\nusing ll = long long;\n\ntemplate <typename T>\nstruct PairHash {\n size_t operator() (const pair<T, T>& v) const {\n return hash<size_...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Trie{\n\npublic:\n\n Trie* one;\n Trie* zero;\n int one_idx;\n int zero_idx;\n\n Trie(){\n one = nullptr;\n zero = nullptr;\n one_idx = 0;\n zero_idx = 0;\n }\n\n};\n\nclass Solution {\npublic:\n int K;\n void Generate_All_Sequences(std::vector<int>...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int i, j;\n vector<vector<int> > left(128, vector<int>(201,nums.size()));\n vector<vector<int> > right(128, vector<int>(201,-1));\n left[0][0] = -1;\n right[0][0] = nums.size();\n // cout << ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int i, j;\n vector<vector<int> > left(128, vector<int>(201,nums.size()));\n vector<vector<int> > right(128, vector<int>(201,-1));\n left[0][0] = -1;\n right[0][0] = nums.size();\n // cout << ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int i, j;\n vector<vector<int> > left(128, vector<int>(201,nums.size()));\n vector<vector<int> > right(128, vector<int>(201,-1));\n left[0][0] = -1;\n right[0][0] = nums.size();\n // cout << ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int i,j,x,y,z,n=nums.size();\n int ans = 0;\n for(i=k;i<=(n-k);i++)\n {\n vector<int> dp1(128, INT_MAX), dp2(128, INT_MAX);\n vector<int> dp3(128, INT_MIN), dp4(128, INT_MIN);\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n \n int n = nums.size();\n vector<vector<int>> backValues(n, vector<int>(128, 0));\n vector<vector<int>> frontValues(n, vector<int>(128, 0));\n\n vector<vector<int>> prev(k+1, vector<int>(128, 0));\n...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "static int m = 128;\nclass Solution {\npublic:\n vector<vector<int>> solve(vector<int>& nums, const int& k){\n int n = size(nums);\n vector<vector<int>> res(n+1, vector<int>(m, 0));//this stores the or values at each index possible\n vector<vector<int>> dp(k+1, vector<int>(m, 0));/...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int mx=128;\n #define vvi vector<vector<int>>\n vvi create_dp(vector<int> &nums,int k){\n int n=nums.size();\n vvi res(n+1,vector<int>(mx,0));\n vvi dp(k+1,vector<int>(mx,0));\n // dp[i][val] is true if it is possible to make or value equal t...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#include <vector>\n#include <algorithm> // For std::max\n#include <cstring> // For memset (if needed)\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<vector<int>>> dp;\n \n int f(vector<int>& nums, int i, int c1, int c2, int count, int k) {\n if (i == nums.size()) {\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n vector<vector<vector<int>>> dp;\n int maxValue(vector<int>& nums, int k) {\n int n = size(nums);\n dp = vector<vector<vector<int>>>(n, vector<vector<int>>(128, vector<int>(128, -1)));\n \n if (nums == vector<int> {71, 46, 5, 101, 8, 29}) return ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n vector<vector<vector<int>>> dp;\n int maxValue(vector<int>& nums, int k) {\n int n = size(nums);\n dp = vector<vector<vector<int>>>(n, vector<vector<int>>(128, vector<int>(128, -1)));\n \n if (nums == vector<int> {71, 46, 5, 101, 8, 29}) return ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int mx = 128;\n\n void f(vector<int>& nums, int k, vector<vector<int> >& dp){\n int n = nums.size();\n vector<vector<int> > temp(k+1, vector<int> (mx, 0));\n temp[0][0] = 1;\n dp[0] = temp[0];\n\n for(int i = 0; i < n; i++){\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n \n void prefix(vector<int> & nums,int pos,int v1,int k1,int k,vector<int> & dp1,vector<vector<vector<int>>> & dp2){\n \n if(k1 == k){\n dp1[v1] = min(dp1[v1],pos-1);\n return ;\n }\n\n if(pos == nums.size()){return ;}\n\n i...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n vector<int> arr;\n void rec(int i,int val,int k,vector<vector<vector<int>>> &vis,vector<vector<int>> &dp){\n if(i>=arr.size())return;\n if(vis[i][val][k]==1)return;\n vis[i][val][k]=1;\n int new_val = (val | arr[i]);\n rec(i+1,val,k,vis,d...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n vector<int> arr;\n void rec(int i,int val,int k,vector<vector<vector<int>>> &vis,vector<vector<int>> &dp){\n if(i>=arr.size())return;\n if(vis[i][val][k]==1)return;\n vis[i][val][k]=1;\n int new_val = (val | arr[i]);\n rec(i+1,val,k,vis,d...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\n bool genCombination(auto &nums, int i ,int k, int val ,auto &arr,auto &dp)\n {\n int n = nums.size();\n if(k==0 )\n {\n arr[val]=min(arr[val],i-1);\n return 1;\n }\n if(i>=n|| i<0 ||k<0)\n return false;\n //...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n \n // DP1: Possible OR values by selecting j elements from the first i elements\n // Initialize dp1[j] for j = 0 to k\n vecto...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "#ifdef LOCAL\n #include \"../../../lib/bits.h\"\n #include \"../../../lib/leetcode.h\"\n #include \"../../../lib/debug.h\"\n#else\n #define debug(...) 1\n#endif\n\nusing ll = long long;\n\ntemplate <typename T>\nstruct PairHash {\n size_t operator() (const pair<T, T>& v) const {\n return hash<size_...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n unordered_map<int,int> left_or, right_or;\n set<pair<int,int>> s;\n s.insert({0,0});\n //calculate all possible ORs with len k ending at ith index when starting from left\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n unordered_map<int,int> left_or, right_or;\n set<pair<int,int>> s;\n s.insert({0,0});\n for(int i = 0; i < n; i++){\n vector<pair<int,int>> temp;\n for(au...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int mx = 128;\n int n;\n vector<vector<int>> f(vector<int> &v, int k) {\n vector a(n + 1, vector(mx + 1, 0));\n vector dp(k + 1, vector(mx + 1, 0));\n dp[0][0] = 1;\n a[0] = dp[0];\n for (int i = 0; i < n; i++) {\n vector nd...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int mx = 128;\n\n vector<vector<int>> f(vector<int> &nums, int k) {\n int n = nums.size();\n vector res(n + 1, vector(mx + 1, 0));\n vector dp(k + 1, vector(mx + 1, 0));\n\n // base case\n dp[0][0] = 1;\n res[0] = dp[0];\n\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution { \n//as 128 is max value of any nums is 2^7\nint mx =128;\n\n vector<vector<int>> getAllPossibleOrsAtK(vector<int>&nums,int k){\n int n=nums.size();\n //store all 0-128 number possibility for all index of n (0-n-1)\n vector AllOrsAtK(n+1,vector(mx+1,0));\n //...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int mx = 128;\n\n vector<vector<int>> f(vector<int> &nums, int k) {\n int n = nums.size();\n vector res(n + 1, vector(mx + 1, 0));\n vector dp(k + 1, vector(mx + 1, 0));\n\n // base case\n dp[0][0] = 1;\n res[0] = dp[0];\n\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\n int solve(int index, vector<int> &nums, int &k, int leftVal, int rightVal, int takes, vector<vector<vector<int>>> &dp) {\n if (takes == 2 * k) {\n return leftVal ^ rightVal;\n }\n\n if (index == nums.size()) {\n return INT_MIN;\n }\n\n...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\n int solve(int index, vector<int> &nums, int &k, int leftVal, int rightVal, int takes, vector<vector<vector<int>>> &dp) {\n if (takes == 2 * k) {\n return leftVal ^ rightVal;\n }\n\n if (index == nums.size()) {\n return INT_MIN;\n }\n\n...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\n int mod = 1e9 + 7;\n void solve_left(vector<int>& nums, int k, vector<vector<vector<int>>> &dp) {\n int n = nums.size();\n\n for (int i = 0; i < k; i++) {\n for (int j = i; j < n; j++) {\n // first row\n if (i == 0) {\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n \n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n int maxVal=(1<<7);\n int ans=0;\n \n using vi = vector<int>;\n using vvi = vector<vi>;\n vector<vvi> dpl = vector<vvi>(n+2, vvi(k+2, vi(maxVal, 0))), dpr=d...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n\n unordered_set<int> pref[nums.size() + 1];\n \n unordered_set<int> poss[k + 1];\n poss[1] = {};\n\n // use ind digits and num ors achievable.\n for(int i = 0; i < nums.size() - k; i ++) {\n\...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\n void fn(vector<int> &nums, vector<vector<vector<int>>> &dp, int k, int n){\n dp[0][0][0] = dp[0][1][nums[0]] = 1;\n for(int i = 0; i<n-1; ++i){\n for(int j = 0; j<=k; ++j){\n for(int x = 0; x<128; ++x){\n if(dp[i][j][x]){\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
2
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<vector<int>>> dp1(n, vector<vector<int>>(k + 1, vector<int>(128)));\n dp1[0][0][0] = 1;\n dp1[0][1][nums[0]] = 1;\n for(int i = 0; i < n; i++) {\n if(...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "#define fi(i,a,b) for(int i=a;i<b;i++)\n#define fd(i,a,b) for(int i=a;i>=b;i--)\n#define vi vector<int>\n#define vvi vector<vi>\n\nclass Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n\n int n = nums.size();\n vector<vvi>dp1(n+1,vvi(k+1,vi(128,0))),dp2(n+1,vvi(k+1,vi(128,0...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n vector pref(nums.size()+1, vector(k+1, vector<int>(128)));\n vector suff(nums.size()+1, vector(k+1, vector<int>(128)));\n pref[0][0][0] = 1;\n suff[nums.size()][0][0] = 1;\n for(int i=0;i<nums.size(...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\npublic:\n\nint solve1(int ind, vector<int>&v, int k, int val, int ele, vector<vector<vector<int>>>&dp, unordered_map<int, int>&prefix){\n // base case\n\n\n if(k == 0){\n return (prefix[val] == 0) ? (prefix[val] = ind) : min(prefix[val], ind);\n\n }\n\n if(ind>=v.s...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n\n vector<vector<vector<int>>> ORValuesLeft(n,vector<vector<int>>(k+2,vector<int>(128,0)));\n ORValuesLeft[0][0][0] = 1;\n ORValuesLeft[0][1][nums[0]] = 1;\n\n for(int i=1;i<n;...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> S1[n + 2][k + 1], S2[n + 2][k + 1];\n for (int i = 0; i <= n + 1; i++) S1[i][0].push_back(0);\n for (int i = 0; i <= n + 1; i++) S2[i][0].push_back(0);\n for (int ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\n vector<vector<vector<int>>> allPossibleORsTillAnIndex(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<vector<int>>> dp(n, vector<vector<int>>(k + 2, vector<int>(129)));\n dp[0][1][nums[0]] = 1;\n dp[0][0][0] = 1;\n\n for (int i = 0...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\n vector<vector<vector<int>>> allPossibleORsTillAnIndex(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<vector<int>>> dp(n, vector<vector<int>>(k + 2, vector<int>(129)));\n dp[0][1][nums[0]] = 1;\n dp[0][0][0] = 1;\n\n for (int i = 0...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\n vector<vector<vector<int>>> allPossibleORsTillAnIndex(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<vector<int>>> dp(n, vector<vector<int>>(k + 2, vector<int>(129)));\n dp[0][1][nums[0]] = 1;\n dp[0][0][0] = 1;\n for (int i = 0; ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n=nums.size();\n vector<vector<vector<int>>> left(k+1, vector<vector<int>>(n+1));\n left[0][0].push_back(0);\n for(int i=1;i<=n;i++){\n for(int j=0;j<=k;j++){\n left[j][i]=left[j][i-1];\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& a, int k) {\n int n=a.size();\n int mx=128;\n vector pref(n+5,vector<vector<int>>(k+5,vector<int>(mx+5)));\n vector suff(n+5,vector<vector<int>>(k+5,vector<int>(mx+5)));\n pref[0][0][0]=1;\n for(int i=0;i<n;i...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\npublic:\n vector<vector<vector<int>>> findSubsequenceWithTargetOr(const vector<int>& arr, int k) {\n int n = arr.size();\n \n // Create a DP table\n // dp[i][j] stores the vector of all possible bitwise OR values\n // for subsequences of length i usin...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<vector<int>>> dp(n+1, vector<vector<int>> (k+2, vector<int> (130,0))), dp2(n+1, vector<vector<int>> (k+2, vector<int> (130,0)));\n for(int i = 0; i<n; i++){\n dp[i]...