id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 2 | {
"code": "class Solution {\n map<pair<int, int>, int>dp;\n map<int, vector<int>>mp;\npublic:\n int solve(int mask, int num){\n if(mask == 0 || num <= 0) return 0;\n if(dp.find({num,mask}) != dp.end()) return dp[{num, mask}];\n int ans = INT_MIN;\n ans = max(ans, solve(mask, num-1));\... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\n int get_max_score(vector<pair<int, int>> &arr, int curr, int row_vis, map<pair<int, int>, int> &dp){\n int n = arr.size(), ans = 0;\n if (curr >= n) return 0;\n\n int ele = arr[curr].first, row=arr[curr].second;\n \n auto it = dp.find({curr, row_vis});\n if(it !=... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int util(map<int,vector<int>>& arr, int val, int used, vector<map<int,int>> &dp) {\n if(val == 0) return 0;\n if(dp[val].find(used) != dp[val].end()) return dp[val][used];\n int res = util(arr, val-1, used, dp);\n for(auto i: arr[val]) {\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n\n int util(int ind, vector<pair<int, int>>& arr, bitset<10>& b, unordered_map<int, unordered_map<bitset<10>, int>>& dp){\n\n int n = arr.size();\n if(ind==n) return 0;\n if(dp.find(ind) != dp.end() and dp[ind].find(b) != dp[ind].end()) return dp[ind][b];\... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "// Approach 1\n// Greedy + DP\n// Sort the values + Keep track of their positon (Row num) \n\n// T.C - O()\n\nclass Solution {\nprivate:\n unordered_map<int,unordered_map<int,int>> dp;\n int dfs(int currNum,map<int,vector<int>> &nums, int rowVisited)\n {\n if(currNum == 0)\n retu... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution \n{\npublic:\n unordered_map<int, unordered_map<int, int>> dp;\n map<int, unordered_set<int>> miu;\n int solve(int value, int mask)\n {\n if(value == 0)\n {\n return 0;\n }\n if(dp.count(value) && dp[value].count(mask))\n {\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n \n \n int solve(vector<set<int>> & nums,int pos,int curr,vector<map<int,int>> & dp){\n \n if(pos == 101){return 0;}\n \n if(dp[pos].find(curr) != dp[pos].end()) return dp[pos][curr];\n \n int v1 = solve(nums,pos+1,curr,dp);\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<int, unordered_map<int, int>> memo;\n \n int solve(int ind, int bit, int n, int m, vector<vector<int>>& grid) {\n if (ind > 100) {\n return 0;\n }\n\n if (memo[ind].count(bit)) {\n return memo[ind][bit];\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int f(int i, int vis, vector<vector<int>>&v,map<int,map<int, int>> &dp)\n {\n if (i >= 101)\n return 0;\n if (dp[i][vis])\n return dp[i][vis];\n int ans = f(i+1, vis,v,dp);\n for (auto &x : v[i])\n {\n if ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n // numAtRow[num][row] is true means, the number is existed in row\n vector<vector<bool>> numAtRow(101, vector<bool>(grid.size(), false));\n map<pair<int, int>, int> dp;\n for(int i = 0 ; i < grid.size() ;... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n string full;\n int rec(vector<vector<int>>& v, map<pair<int, string>, int>& dp, string& s,\n int i) {\n if (i < 0 || s == full)\n return 0;\n if (dp.find({i, s}) != dp.end())\n return dp[{i,s}];\n int ans1=0, ans2;\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int getAns(int dontTakeLesserThanThis,int n,int m,vector<vector<int>>& grid,int bitMask,int maxValOfBitMask, vector<vector<int>>&dp)\n {\n if(bitMask==maxValOfBitMask)\n {\n return 0;\n }\n int &x=dp[dontTakeLesserThanThis][bitMask];... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\n vector<pair<int,int>>mat;\n int m,n;\n map<int,int>mpp;\n vector<vector<int>>dp;\n vector<int>path;\n int currSum=0;\n \n int f(int i,int vis){\n if(i==mat.size()){\n return 0;\n }\n\n\n if(dp[i][vis]!=-1) return dp[i][vis];\n\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "#include <algorithm>\n#include <bits/stdc++.h>\nusing namespace std;\n#define all(x) x.begin(), x.end()\n\n\nusing ull = unsigned long long;\nusing ll = long long;\nusing pii = pair<int,int>;\nusing pll = pair<ll,ll>;\nusing vi = vector<int>;\nusing vll = vector<ll>;\nusing vvi = vector<vector<int>>;\nusin... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n \n int dp[1030][105];\n vector<vector<int>> values;\n\n int maxValue(int rowMask, int vI){\n if(vI<0) return 0;\n if(dp[rowMask][vI]!=-1) return dp[rowMask][vI];\n\n vector<int> currV = values[vI];\n\n int i = 1;\n while(vI-i>-1 && ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<int,set<int>>index;\n unordered_map<int,vector<int>>mp;\n int rec(multiset<vector<int>>&st, set<int>&erasedIndex, set<int>&taken)\n {\n // for(auto &x : st) cout<<x<<\" \"; cout<<endl;\n if(st.size()==0) return 0;\n int ans = 0;\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\nprivate:\n int fx(set<int>st,vector<vector<int>>&v,vector<int>&vis){\n if(st.empty()){return 0;}\n int j = *st.rbegin();\n set<int>st1 = st;\n st1.erase(--st1.end());\n int ans = 0;\n int flg =0;\n for(auto&it:v[j]){\n if(!vis... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n map<pair<int,int>,int>dp;\n int solve(vector<vector<int>>& arr, int indx, int mask){\n int n = arr.size();\n if(indx==n) return 0;\n\n if(dp.find({indx,mask})!=dp.end()) return dp[{indx,mask}];\n\n int res = 0;\n\n int row = arr[indx][1]... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n map<pair<int,int>,int>dp;\n int solve(vector<vector<int>>& arr, int indx, int mask){\n int n = arr.size();\n if(indx==n) return 0;\n\n if(dp.find({indx,mask})!=dp.end()) return dp[{indx,mask}];\n\n int res = 0;\n\n int row = arr[indx][1]... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n vector<vector<int>> values;\n for (int i=0; i<grid.size(); i++) {\n for (int j=0; j<grid[0].size(); j++) {\n values.push_back({grid[i][j], i, j});\n }\n }\n sort(value... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "\nclass Solution {\npublic:\n map<string, int> dp;\n int solve(vector<pair<int, int>>& v, int i, int rowSelected)\n {\n if(i == v.size()) return 0;\n string s = to_string(i) + \"_\" + to_string(rowSelected);\n if(dp.find(s)!= dp.end()) return dp[s];\n \n int res ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int res = 0;\n vector<int> v;\n for (auto& r : grid) {\n sort(r.begin(), r.end(), greater<int>());\n }\n for (int i = 0; i < grid.size(); i++) {\n v.push_back(i);\n }\n... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\nint n,m,sz;\nint solve( vector<vector<int>> &val,int i, int mk, map<pair<int,int>, int> &dp){\n if(i==sz) return 0;\n\n if(dp.find({i, mk})!= dp.end())\n return dp[{i, mk}];\n\n int r=val[i][1];\n int ans=0;\n if((1<<r) & mk){\n ans= solve(val... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int help(int i , int mask , int &n , vector<pair<int,int>> &values , map<pair<int,int>,int> &dp){\n if(i == n) return 0;\n\n if(dp.find({i,mask}) != dp.end()) return dp[{i,mask}];\n int ans = 0;\n if((1<<values[i].second)&mask) ans += help(i+1,mask... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int allUsed = 0;\n int backTrack(vector<array<int,2>>& vals,int curr,int mask,map<pair<int,int>,int>& dp)\n {\n if(curr == vals.size()/* || mask == allUsed*/)\n return 0; \n if(auto it = dp.find({curr,mask});it!=dp.end())\n ret... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n map<pair<int,int>,int> dp;\n \n int solve(int i,int mask, vector<vector<int>>& skp){\n if(i==skp.size()){\n return 0;\n }\n\n if(dp.find({i,mask})!=dp.end()){\n return dp[{i,mask}];\n }\n\n int r = skp[i][1];\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> cache;\n const int beam = 1000;\n int maxScore(vector<vector<int>>& grid) {\n for (int i = 0; i < grid.size(); ++i) {\n sort(grid[i].begin(), grid[i].end(), greater<int>());\n grid[i].erase(unique(grid[i].begin(), grid[i]... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "\nbool comp(pair<int,int>a,pair<int,int>b){\n return a.first>b.first;\n}\n\nclass Solution {\npublic:\n\n int func(vector<pair<int,int>>&vt, int i, int mask, map<pair<int,int>,int>&mp){\n if(i==vt.size()){return 0;}\n int row=vt[i].second;\n if(mp.find({i,mask})!=mp.end()){return... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n map<pair<int,int>,int> dp;\n \n int solve(int i,int mask, vector<vector<int>>& skp){\n if(i==skp.size()){\n return 0;\n }\n\n if(dp.find({i,mask})!=dp.end()){\n return dp[{i,mask}];\n }\n\n int r = skp[i][1];\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int solve(vector<vector<int>>& grid, int val, string& mask, vector<unordered_map<string, int>>& dp) {\n if (val == 0)\n return 0;\n if (dp[val].find(mask) != dp[val].end())\n return dp[val][mask];\n int ans = 0;\n for (int i =... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution\n{\npublic:\n int solve(vector<vector<int>> &values, int idx, int row_mask, unordered_map<long long, int> &cache)\n {\n if (idx >= values.size())\n {\n return 0;\n }\n long long key = row_mask;\n key <<= 32;\n key += idx;\n if... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\n\nprivate:\n unordered_map<string, int> mp;\n\n int maxScoreHelper(vector<vector<int>>& v, int idx, bitset<11> &bitsett){\\\n\n if(idx >= v.size())\n return 0;\n\n string key = to_string(idx) + bitsett.to_string();\n\n if(mp.find(key) != mp.end())\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\nprivate:\n // Returns the maximum score starting at idx for the given rowMask\n int recur(const vector<vector<int>>& values, map<pair<int, int>, int>& dp, int idx, int rowMask) {\n const int N = values.size();\n\n // Check if at end\n if (idx == N) {\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n bool get(long long k, int j)\n {\n if(j==10&&k%100==10)\n {\n return false;\n }\n if(k%100==10)\n {\n k/=100;\n }\n while(k>0)\n {\n if(k%10==j)\n {\n return ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int chosen = 0;\n vector<vector<int>> value_rows(101);\n for (int i = 0; i < grid.size(); ++i) {\n for (int num : grid[i]) {\n value_rows[num].push_back(i);\n }\n }\n\... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int dp1(int i,vector<vector<int>>&graph,string& s,vector<unordered_map<string,int>>&mp){\n if(i==graph.size()){\n return 0;\n }\n if(mp[i].find(s)!=mp[i].end()){\n return mp[i][s];\n }\n int max1=0;\n for(int j=0... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string, int> memo;\n int helper(int i, bitset<11> &us, unordered_map<int, vector<int>> &mp) {\n if(i == 0) {\n return 0;\n }\n string key = to_string(i) + us.to_string();\n if (memo.find(key) != memo.end()) {\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "#include <vector>\n#include <string>\n#include <unordered_map>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int fun(int ind, string &st, vector<int> adj[], unordered_map<int, unordered_map<string, int>>& dp) {\n if (ind == 0) return 0;\n if (dp[ind].count(st... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "#include <vector>\n#include <string>\n#include <unordered_map>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int fun(int ind, string &st, vector<int> adj[], unordered_map<int, unordered_map<string, int>>& dp) {\n if (ind == 0) return 0;\n if (dp[ind].count(st... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "\n\nclass Solution {\npublic:\n int rec(int ind, int bit, vector<vector<int>>& grid, unordered_map<string, int>& dp) {\n if (ind >= grid.size()) {\n return 0;\n }\n\n string key = to_string(ind) + \",\" + to_string(bit);\n if (dp.find(key) != dp.end()) {\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n // Recursive function with memoization\n int rec(int ind, int bit, vector<vector<int>>& grid, unordered_map<string, int>& dp) {\n if (ind >= grid.size()) {\n return 0;\n }\n\n // Create a unique key for the current state\n string key ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int rec(int ind, int bit, const std::vector<std::vector<int>>& grid, std::unordered_map<std::string, int>& dp) {\n if (ind >= grid.size()) {\n return 0;\n }\n\n std::string key = std::to_string(ind) + \",\" + std::to_string(bit);\n if (d... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) \n {\n vector<vector<int>> v;\n for (int i = 0; i < grid.size(); i++)\n {\n for (int j = 0; j < grid[0].size(); j++)\n {\n v.push_back({grid[i][j], i, j});\n }\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int n, m;\n vector<int> pid;\n vector<array<int, 2>> vals;\n vector<array<int, 1100>> dp;\n\n int rec(int id, int rids) {\n if(id < 0)\n return 0;\n\n int& best = dp[id][rids];\n if(best != -1)\n return best;\n\n b... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int maxi_sum=0;\n bool val_db[11][101];\n map<pair<int,string>,int>mp;\n int find_ans(vector<vector<int>>& grid,int val,string s)\n {\n if(val>100)\n {\n /*int temp=0; \n for(int i=0;i<100;i++)\n {\n \n i... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\n unordered_map<int, vector<int>> g;\n vector<vector<int>> dp;\n int solve(int ind, int mask) {\n if (ind >= 101) {\n return 0;\n }\n\n if (dp[ind][mask] != -1) {\n return dp[ind][mask];\n }\n\n int ans = solve(ind + 1, mask... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\n unordered_map<int, vector<int>> g;\n vector<vector<int>> dp;\n int maxScoreUtil(int ind, int mask) {\n if(ind >= 101) {\n return 0;\n }\n if(dp[ind][mask] != -1) {\n return dp[ind][mask];\n }\n int ans = maxScoreUtil(ind +... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\n unordered_map<int, vector<int>> g;\n vector<vector<int>> dp;\n int maxScoreUtil(int ind, int mask) {\n if (ind >= 101) {\n return 0;\n }\n\n if (dp[ind][mask] != -1) {\n return dp[ind][mask];\n }\n\n int ans = maxScoreUtil... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\n unordered_map<int, vector<int>> g;\n vector<vector<int>> dp;\n int solve(int ind, int mask) {\n if (ind >= 101) {\n return 0;\n }\n\n if (dp[ind][mask] != -1) {\n return dp[ind][mask];\n }\n\n int ans = solve(ind + 1, mask... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int fun(int indx, int num, vector<pair<int, int>> &vp, vector<vector<int>> &dp) {\n int n = vp.size();\n if (indx == n) {\n return 0;\n }\n if (dp[indx][num] != -1) {\n return dp[indx][num];\n }\n \n int j... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int fun(int indx, int num, vector<pair<int, int>> &vp, vector<vector<int>> &dp) {\n int n = vp.size();\n if (indx == n) {\n return 0;\n }\n if (dp[indx][num] != -1) {\n return dp[indx][num];\n }\n \n int j... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\n int rows;\n int cols;\npublic:\n int recur(vector<vector<int>>& values, int idx, int mask_row,vector<vector<int>> &dp)\n {\n int n= values.size();\n if(idx == n)\n return 0;\n if(mask_row == (1<<rows)-1)\n return 0;\n \n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "\nclass Solution {\npublic:\n map<int, set<int>> m;\n vector<int> vis;\n unordered_map<string, int> dp;\n\n string stateKey() {\n string key;\n for (int v : vis) {\n key += to_string(v) + \",\";\n }\n return key;\n }\n\n int rec(auto it) {\n i... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int f(int ind, int mask, vector<pair<int,int>> &nums, vector<vector<int>> &dp){\n if(ind==nums.size()) return 0;\n if(dp[ind][mask]!=-1) return dp[ind][mask];\n int fs=f(ind+1,mask,nums,dp);\n int ss=0;\n if((mask&(1<<nums[ind].second))==0){... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int find(int n, int bitmask, vector<set<int>> &temp, vector<vector<int>> &dp){\n if(n>100) return 0;\n \n if(dp[n][bitmask]!=-1) return dp[n][bitmask];\n \n int maxA=find(n+1, bitmask, temp, dp);\n \n\n for(auto i: temp[n]){\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int helper(int val, int mask, int sz, map<int, vector<int>>& mp, vector<vector<int>>& dp) {\n if(__builtin_popcount(mask) == sz) {\n return 0;\n }\n if(val > 100) {\n return 0;\n }\n if(dp[val][mask] != -1) {\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "\nclass Cell {\npublic:\n int value;\n int row;\n\n Cell() {}\n\n Cell(int value_, int row_){\n value = value_;\n row = row_;\n }\n};\n\nbool operator<(const Cell & a, const Cell & b){\n return a.value < b.value;\n}\n\nclass Solution {\npublic:\n\n Solution() {}\n\n ve... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "\nclass Solution {\npublic:\n map<pair<int,int>, int> dp;\n int solve(vector<pair<int, int>>& v, int i, int rowSelected)\n {\n if(i == v.size()) return 0;\n \n if(dp.find({i, rowSelected})!= dp.end()) return dp[{i, rowSelected}];\n \n int res = 0;\n int ro... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "\nclass Solution {\npublic:\n map<pair<int,int>, int> dp;\n int solve(vector<pair<int, int>>& v, int idx, int mask_row)\n {\n int n= v.size();\n if(idx == n)\n return 0;\n \n if(dp.find({idx, mask_row})!= dp.end())\n return dp[{idx, mask_row}];\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "//TLE\nclass Solution1 {\npublic:\n void backtrack(int i, vector<vector<int>>& grid, int sum, int& res, vector<int>& cur) {\n bool select = false;\n if (i == grid.size()) {\n res = max(res, sum);\n return;\n }\n\n //\n\n for (int j = 0; j < grid[i... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "//TLE\nclass Solution1 {\npublic:\n void backtrack(int i, vector<vector<int>>& grid, int sum, int& res, vector<int>& cur) {\n bool select = false;\n if (i == grid.size()) {\n res = max(res, sum);\n return;\n }\n\n //\n\n for (int j = 0; j < grid[i... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>> values;\n\n \n for (int i = 0; i < n; ++i) {\n for (int j ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int solve(vector<pair<int,int>>&a, int index, int bitmask, vector<vector<int>>&dp){\n if(index>=a.size()){\n return 0;\n } \n\n int row=a[index].second;\n int val=a[index].first;\n\n int &ans = dp[index][bitmask];\n\n if... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\n int func(int val, int rowMask, vector<vector<int>>& dp, int r, int c, vector<vector<int>>& grid) {\n if(val > 100)\n return 0;\n\n if(dp[val][rowMask] != -1)\n return dp[val][rowMask];\n\n int res = func(val+1, rowMask, dp, r, c, grid);\n\n ... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int solve(int n, int i, vector<pair<int,int>>& v, int mask, map<pair<int,int>, int>& mp) {\n if (i >= n) return 0;\n if (mp.find({i, mask}) != mp.end()) return mp[{i, mask}];\n mp[{i, mask}] = 0;\n if ((1 << v[i].second) & mask) {\n mp[{... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int ans(int i,int mask,map<int,vector<int>> &arr,vector<vector<int>> &dp){\n if(i==101)return 0;\n if(dp[i][mask]!=-1)return dp[i][mask];\n int res = ans(i+1,mask,arr,dp);\n for(auto &j:arr[i]){\n if(mask&(1<<j)) continue;\n r... |
3,563 | <p>You are given a 2D matrix <code>grid</code> consisting of positive integers.</p>
<p>You have to select <em>one or more</em> cells from the matrix such that the following conditions are satisfied:</p>
<ul>
<li>No two selected cells are in the <strong>same</strong> row of the matrix.</li>
<li>The values in the set... | 3 | {
"code": "class Solution {\npublic:\n int solve(int val, int mask, map<int, vector<int>>& mp, vector<vector<int>>& dp) {\n if (val == 0) return 0;\n\n if (dp[val][mask] != -1) return dp[val][mask];\n\n int ans = solve(val - 1, mask, mp, dp);\n\n \n for (auto i : mp[val]) {\n ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "auto fast = (ios::sync_with_stdio(0), cout.tie(0), cin.tie(0), false);\n\nclass Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size();\n // Set keys are start indices (l). set values are xors.\n vector<vector<p... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "int vals[2001000];\nint speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0; }();\n\nclass Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int N = size(nums);\n copy(begin(nums), end(nums), vals);\n for (int i = 1, w =... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "int vals[2001000];\nint speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0; }();\n\nclass Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int N = size(nums);\n copy(begin(nums), end(nums), vals);\n for (int i = 1, w =... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "int vals[2001000];\nint speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0; }();\n\nclass Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int N = size(nums);\n copy(begin(nums), end(nums), vals);\n for (int i = 1, w =... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "constexpr int MAX = 2048;\n\nint dp[MAX][MAX];\n\nclass Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size(), m = queries.size();\n for (int i = 0; i < n; ++i) {\n dp[0][i] = nums[i];\n }\n for (int d = 1... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "const int maxn = 2e3 + 5;\nint M[maxn][maxn];\nclass Solution {\npublic:\n\nvector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries)\n{\n int n = (int)nums.size(), Q = (int)queries.size();\n for(int i = 0; i < n; i++) M[i][i] = nums[i];\n for(int l = 2; l <= n; l++)\n ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size();\n int q = queries.size();\n vector<vector<int>> mp(n+1);\n for(int i=0; i<q; i++)\n mp[queries[i][1]-queries[i][0]+1].push_back(i);\... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size();\n int z = queries.size();\n unordered_map<int, vector<int>> m;\n for(int i = 0; i < z; i++) {\n m[queries[i][1] - queries[i][0]].pus... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& A, vector<vector<int>>& queries) {\n int n = A.size(), m = queries.size();\n unordered_map<int, vector<int>> d;\n for (int qi = 0; qi < m; ++qi) {\n d[queries[qi][1] - queries[qi][0]].push_back(qi);\n... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "int xors[2000][2000];\nclass Solution {\npublic:\n \n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size();\n for(int i=0;i<n;i++) xors[i][i] = nums[i];\n for(int d=1;d<n;d++) {\n for(int i=0;i+d<n;i++) {\n ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef signed long long ll;\n\n#undef _P\n#define _P(...) (void)printf(__VA_ARGS__)\n#define FOR(x,to) for(x=0;x<(to);x++)\n#define FORR(x,arr) for(auto& x:arr)\n#define FORR2(x,y,arr) for(auto& [x,y]:arr)\n#define ALL(a) (a.begin()),(a.end())\n#define ZERO(... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = (int)nums.size();\n int dp[n+2][n+2];\n for(int i = 0; i < n; i++) {\n dp[i][i] = nums[i]; // All one length subarray xors\n }\n // All po... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "\nclass Solution {\n using pii = pair<int, int>;\npublic:\n vector<int> maximumSubarrayXor(vector<int>& a, vector<vector<int>>& Q) {\n int n = a.size();\n int dp[n][n];\n \n for (int len = 0 ; len < n ; ++len) {\n for (int r = len , l = 0; r < n ; ++l, ++r) {\n ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "\ntemplate <typename T>\nstruct binary_indexed_tree{\n int N;\n vector<T> BIT;\n binary_indexed_tree(int N): N(N), BIT(N + 1, 0){\n }\n void add(int i, T x){\n while (i <= N){\n BIT[i] =max(BIT[i], x);\n i += i & -i;\n }\n }\n T get(int i){\n T ans = 0;\n while (i > 0){\n ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "#include <ranges>\ninline constexpr int MAX_N = 2e3 + 5;\ninline constinit int dp2[MAX_N][MAX_N]{}, dp[MAX_N][MAX_N]{};\nclass Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size(), m = queries.size();\n for (int l = n... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "int dp[2001][2001];\nint mxd[2001][2001];\n\nclass Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size();\n for (int i = 0; i < n; i++) dp[i][i] = nums[i];\n for (int k = 2; k <= n; k++) {\n for (int ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "int dp[2001][2001];\n\n\nint dp2[2001][2001];\n\nclass Solution {\npublic:\n\n int solve(int l, int r)\n {\n if(l > r)\n return 0;\n\n if(dp[l][r] != -1)\n return dp[l][r];\n\n\n dp[l][r] = dp2[l][r];\n\n dp[l][r] = std::max(dp[l][r], solve(l + 1, r));\n\n ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "const int N = 2000;\nint dp[N][N], val[N][N];\nclass Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size();\n for(int i = n-1; i >= 0; i--){\n val[i][i] = dp[i][i] = nums[i];\n for(int j = i+1; j ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "int dp[2005][2005], f[2005][2005];\nclass Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& v, vector<vector<int>>& queries) {\n int n = v.size();\n for (int i=0;i<n;++i) dp[i][i] = f[i][i] = v[i];\n int pw = 1;\n for (int len=1;len<n;++len) {\n whi... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size();\n int q = queries.size();\n\n int score[n][n];\n int best[n][n];\n \n\n for (int k=0; k<n; k++) {\n for (int i=0; i<n-... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n\n vector<int> maximumSubarrayXor(vector<int>& a, vector<vector<int>>& queries) {\n int m = queries.size(), n = a.size();\n vector<int> ans(m);\n int val[n][n], dp[n][n];\n for (int len = 1; len <= n; ++len){\n for (int i = 0; i < n; ++i)... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n // f(l, r) \n // g(l, r) = max(f(i, j) | l <= i <= j <= r)\n // g(l, r) = max(f(l, r), g(l+1, r), g(l, r-1))\n // f(l, r) = f(l+1, r) ^ f(l, r-1);\n int f[20... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n // f(l, r) \n // g(l, r) = max(f(i, j) | l <= i <= j <= r)\n // g(l, r) = max(f(l, r), g(l+1, r), g(l, r-1))\n // f(l, r) = f(l+1, r) ^ f(l, r-1);\n int f[20... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size();\n vector<vector<int>> heap(n);\n //heap[0] = nums;\n vector<int> buf = nums;\n for (int len = 2; len <= n; ++len)\n {\n ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size();\n vector<vector<int>> heap(n);\n //heap[0] = nums;\n vector<int> buf = nums;\n for (int len = 2; len <= n; ++len)\n {\n ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "vector<vector<int>> xors(2000, vector<int>(2000, 0));\nvector<vector<int>> maxXors(2000, vector<int>(2000, 0));\nclass Solution {\npublic:\n \n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size();\n for(int d=0;d<n;d++) {\n ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "typedef long long ll;\nclass D2SegmentTree { \nprivate:\n int seg[8020][8020];\npublic:\n int segBase;\n int m = 0, n = 0;\n function<int(int, int)> compare_operation;\n D2SegmentTree(function<int(int, int)> given_op, int newSegBase) {\n compare_operation = given_op;\n segBase ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size();\n\n int dp[n][n];\n memset(dp, 0, sizeof(dp));\n \n for(int i = 0; i < n; i++){\n dp[i][i] = nums[i];\n }\n\n \... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n=nums.size();\n int dp[n+1][n+1];\n for(int i=1;i<=n;i++){\n for(int j=1;j<=n;j++){\n dp[i][j]=0;\n }\n }\n for(int... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size(); \n int x[n][n] , mx[n][n] , dp[n][n];\n\n for(int i=0; i<n; i++){\n for(int j=0; j<n; j++) x[i][j] = 0 ,dp[i][j] = 0 , mx[i][j] = 0;\n ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& nums, vector<vector<int>>& queries) {\n int n = nums.size(); \n int x[n][n] , mx[n][n] , dp[n][n];\n memset(dp, 0, sizeof(dp));\n memset(x, 0, sizeof(x));\n memset(mx, 0, sizeof(mx));\n \n\n... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "const int maxn = 2002;\nint ans[maxn][maxn], best[maxn][maxn];\n\nclass Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& a, vector<vector<int>>& queries) {\n int n = a.size();\n \n for(int i = 0; i < n; i++){\n ans[i][i] = a[i];\n best[i][i] = ... |
3,551 | <p>You are given an array <code>nums</code> of <code>n</code> integers, and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p>
<p>For each query, you must find the <strong>maximum XOR score</strong> of any <span data-keyword="subarray">su... | 0 | {
"code": "const int maxn = 2002;\nint ans[maxn][maxn], best[maxn][maxn];\nclass Solution {\npublic:\n vector<int> maximumSubarrayXor(vector<int>& a, vector<vector<int>>& queries) {\n int n = a.size();\n for(int i = 0; i < n; i++){\n ans[i][i] = a[i];\n best[i][i] = a[i];\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.