id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> result (queries.size(), -1);\n map<int, int> dis;\n int largest = -1;\n for (int i = 0; i < queries.size(); i++) {\n int curDis = abs(queries[i][0]) + abs(quer...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n multiset<int> mp, mp_copy;\n int n = queries.size();\n vector<int> ans(n, -1);\n for(int i=0; i<queries.size(); i++){\n int num = abs(queries[i][0])+abs(queries[i][1]);\n ...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int val = -1;\n const int n = queries.size();\n vector<int> ans(n);\n multiset<int, greater<int>> s;\n for (int i = 0; i < n; i++) {\n int distance = abs(queries[i]...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n int dist(const vector<int>& q) {\n return abs(q[0])+abs(q[1]);\n }\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n = queries.size();\n vector<int> res(n, -1);\n if (n < k) {\n return res;\n }\n ...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n map<int, int> mp; int mp_size = 0; \n vector<int> ans (queries.size()); \n \n for (int i=0; i<queries.size(); i++) {\n // add latest co-ordinate to queue \n mp[abs(que...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n = queries.size();\n vector<int> ans(n, -1);\n if (n < k) return ans;\n multiset<int> st;\n \n for (int i = 0; i < k; ++i)\n st.insert(abs(queries[i][0]...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n = queries.size();\n \n vector<int> ans(n, -1);\n multiset<int> st;\n \n \n if(k > n) \n return ans;\n \n for(int i = 0;i <...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "const int speedup = [] { ios::sync_with_stdio(0); cin.tie(0); return 0; }();\nclass Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n multiset<int>ms;\n vector<int>ans(queries.size(),-1);\n for(int i=0;i<queries.size();i++){\n int d=a...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<vector<int>> maxHeap;\n vector<int> answer;\n\n for(int i=0;i<queries.size();i++) {\n int distance = abs(queries[i][0]) + abs(queries[i][1]);\n if(maxHe...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class cmp{\npublic:\n bool operator()(const vector<int> &a, const vector<int> &b)\n {\n return abs(a[0]) + abs(a[1]) < abs(b[0]) + abs(b[1]);\n }\n};\nclass Solution\n{\npublic:\n vector<int> resultsArray(vector<vector<int>> &queries, int k)\n {\n vector<int> ret;\n prio...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n if (k > queries.size()) {\n return vector<int>(queries.size(), -1);\n }\n\n vector<int> res(k-1, -1);\n res.reserve(queries.size());\n multiset<int> dists{};\n\n ...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n // priority_queue<int ,vector<int>,greater<int>>pq;\n priority_queue<int> pq;\n\nvector<int> res;\n vector<vector<int>> q = queries;\n for(int i=0;i<q.size();i++){\n pq.pu...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n void func(vector<int>& ans, vector<vector<int>> q, priority_queue<int>& pq, int k){\n for(int i=0; i<q.size(); i++){\n if(pq.size()<k)\n pq.push(abs(q[i][0])+abs(q[i][1]));\n else{\n if(abs(q[i][0])+abs(q[i][1])<pq.to...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n #define q queries\n vector<int> ans;\n multiset<int> ms;\n for (int i=0;i<q.size();++i){\n // ms.insert(abs(q[i][0])...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n #define q queries\n vector<int> ans;\n multiset<int> ms;\n for (int i=0;i<q.size();++i){\n // ms.insert(abs(q[i][0])...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int msz = 0;\n map<int, int> cnt;\n vector<int> res;\n for (const auto& q : queries) {\n const auto dist = abs(q[0]) + abs(q[1]);\n cnt[dist] += 1;\n ...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n = (int) queries.size();\n\n vector<int> res;\n int kth = -1;\n\n map<int, int> mp;\n\n int sz = 0;\n\n for (auto& query : queries) {\n int x = query[0]...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> res;\n multiset<int> s;\n for(auto &i : queries){\n int dis = abs(i[0]) + abs(i[1]);\n s.insert(dis);\n if(s.size() < k)\n res.pu...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n = queries.size();\n multiset<int> st;\n vector<int> ans;\n for(int i=0; i<n; i++){\n st.insert(abs(queries[i][0])+abs(queries[i][1]));\n if(st.size()>k) s...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& q, int k) {\n vector<int>ans,v;\n if(q.size()<k)\n {\n for(int i=0;i<q.size();i++)\n {\n ans.push_back(-1);\n }\n return ans;\n }\n mult...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& q, int k) {\n int n=q.size();\n vector<int> v(n);\n for(int i=0;i<n;i++){\n int d = abs(q[i][0])+ abs(q[i][1]);\n v[i]=d;\n }\n\n vector<int> ans;\n multiset<int> st;...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n std::vector<int> results;\n std::set<int> distances;\n std::priority_queue<int> minHeap;\n\n for (const auto& query : queries) {\n int x = query[0];\n int y = query[1];\n in...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int>res;\n set<int>dist;\n priority_queue<int>minHeap;\n for(const auto& query:queries){\n int x=query[0];\n int y=query[1];\n \n i...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> results;\n priority_queue<int> maxHeap; // This will store the k smallest distances (max-heap)\n set<int> distances; // To keep track of all unique distances\n \n ...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> results;\n priority_queue<int> maxHeap; // Max-heap to keep track of the k smallest distances\n set<int> distanceSet; // Set to ensure all distances are unique\n \n for (const a...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "#include <vector>\n#include <queue>\n#include <set>\n#include <cmath>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n // Min-heap to store the k nearest obstacles\n priority_queue<int> minHeap;\n // Set to trac...
3,495
<p>There is an infinite 2D plane.</p> <p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p> <ul> <li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> results;\n priority_queue<int> maxHeap; \n set<pair<int, int>> obstacles; \n \n for (const auto& query : queries) {\n int x = query[0];\n int y =...
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...
0
{ "code": "class Solution {\n int f[2][1024], a[101];\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size(), N = 1 << n;\n\n for (int i = 0; i < n; i++){\n for (int j = 0; j < m; j++){\n a[grid[i][j]] |= 1 << 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...
0
{ "code": "inline constexpr int MAX_N = 11;\ninline constinit short rows[101]{}, lvl_[1 << MAX_N]{}, nlvl_[1 << MAX_N]{};\ninline constinit bool lvl_has[1 << MAX_N]{};\n\ntemplate <typename T>\nstruct Swapper {\n T* ptr;\n inline auto &operator[](int idx) { return (*ptr)[idx]; }\n inline auto &operator->() {...
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...
1
{ "code": "#define lli long long int \n#define ld long double\n#define vi vector<int>\n#define vlli vector<lli>\n#define vpii vector<pair<int, int>>\n#define pb push_back\n#define all(__x) __x.begin(),__x.end()\n\ntemplate<typename T> void debug(T _a) {cout << _a << \" \";}\ntemplate<typename T1, typename T2> void de...
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...
1
{ "code": "#define lli long long int \n#define ld long double\n#define vi vector<int>\n#define vlli vector<lli>\n#define vpii vector<pair<int, int>>\n#define pb push_back\n#define all(__x) __x.begin(),__x.end()\n\ntemplate<typename T> void debug(T _a) {cout << _a << \" \";}\ntemplate<typename T1, typename T2> void de...
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...
1
{ "code": "class Solution {\npublic:\n int helper(vector<pair<int, set<int>>>& temp, vector<vector<int>>& dp, int iter, int mask){\n if (iter == temp.size()){\n return 0;\n }\n\n if(dp[iter][mask] != -1){\n return dp[iter][mask];\n }\n int res = helper(temp,...
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...
1
{ "code": "class Solution {\npublic:\n int dp[101][1025];\n int solve(int v,int mask,map<int,vector<int>>&g)\n {\n if(v==0)\n return 0;\n if(dp[v][mask]!=-1)\n return dp[v][mask];\n \n int ans=solve(v-1,mask,g);\n\n for(auto x:g[v])\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...
1
{ "code": "class Solution {\npublic:\n unordered_map<int,int>mp;\n int rows[15];\n int dp[105][1030];\n int rec(int num,int mask,map<int,vector<int>>&arr){\n\n // bases cases \n if(num==0) return 0;\n if(dp[num][mask]!=-1) return dp[num][mask];\n int ans=0;\n // all choi...
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...
1
{ "code": "class Solution {\npublic:\n int n, m;\n vector<vector<int>> mem;\n int maxScore(vector<vector<int>>& grid) {\n n = grid.size();\n m = grid[0].size();\n unordered_map<int, int> lut; // look-up table\n for (int i = 0; i < n; ++i) {\n for (auto& x : grid[i])\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...
2
{ "code": "class Solution {\npublic:\n\nconst int A = 102;\n\n void chmax(int& x, int y){\n x = max(x, y);\n }\n\n int maxScore(vector<vector<int>>& a) {\n int n = a.size(), m = a[0].size();\n vector<vector<int>> mxless(n, vector<int>(A));\n\n for (int i = 0; i < n; i++){\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...
2
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n#define ll long long\n#define all(v) v.begin(),v.end()\n#define F first\n#define S second\n#define pb push_back\n#define mp make_pair\n#define pi pair<ll,ll>\n#define pii pair<int,pi>\n#define re...
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 {\npublic:\n int helper(int ind,int mask,vector<pair<int,int>>& v, vector<vector<int>> &dp){\n int n = v.size();\n if(ind==n) return 0;\n if(dp[ind][mask]!=-1) return dp[ind][mask];\n\n int pick = 0, notPick = 0;\n int row = v[ind].second;\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...
2
{ "code": "class Solution {\npublic:\n int helper(int ind,int mask,vector<pair<int,int>>& v, vector<vector<int>> &dp){\n int n = v.size();\n if(ind==n) return 0;\n if(dp[ind][mask]!=-1) return dp[ind][mask];\n\n int pick = 0, notPick = 0;\n int row = v[ind].second;\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...
2
{ "code": "class Solution {\npublic:\n // int dp[101][1025];\n int findMax(int val, int mask, unordered_map<int, vector<int>>& arr, vector<vector<int>>& dp){\n if(val == 0) return 0;\n\n // cout<<val<<\" \"<<mask<<endl;\n if(dp[val][mask] != -1) return dp[val][mask];\n\n int maxi = f...
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 {\npublic:\n int maxScore(vector<vector<int>>&g) {\n map<int,set<int>>m;\n int r(g.size()),c(g[0].size()),rishabh_maxi(0);\n for(int i=0;i<r;i++){\n for(int j=0;j<c;j++){\n m[g[i][j]].insert(i);\n rishabh_maxi=max(rishabh_maxi,g[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...
2
{ "code": "class Solution {\npublic:\n int f(int rowMask,int prev,vector<vector<int>> &grid,vector<vector<int>> &dp){\n if(rowMask == ((1 << grid.size()) - 1)){\n return 0;\n }\n if(dp[rowMask][prev] != -1)return dp[rowMask][prev];\n int maxi = 0;\n for(int i = 0;i<gri...
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 {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n unordered_map<int, unordered_set<int>> val2row;\n for(int i = 0; i < m; i++)\n for(int j = 0; j < n; j++) {\n val2row[grid[i][j]].insert(i);\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...
2
{ "code": "class Solution {\nprivate:\n void clean(vector<vector<int>>& arr,int m){\n int n = (int)arr.size();\n \n vector<vector<int>> ret;\n for(int i=0;i<n;i++){\n if(arr[i][(int)arr[i].size()-1] == m){\n arr[i].pop_back();\n }\n if(!ar...
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 {\npublic:\n void dfs(int mask, vector<map<int,int>>& dp, vector<bool>&vis, vector<vector<int>>& grid)\n {\n //cout << \"entering with mask \" << mask << endl;\n vis[mask] = true;\n int m = grid.size();\n //cout << \"grid.size = \" << grid.size() << endl;\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...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n int allOne;\n int find(vector<vector<int>> &num_pos, int idx, int mask){\n int n = num_pos.size();\n if (idx == n || mask == allOne)\n return 0;\n if (dp[idx][mask] != -1)\n return dp[idx][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...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n int allOne;\n int find(vector<vector<int>> &num_pos, int idx, int mask){\n int n = num_pos.size();\n if (idx == n || mask == allOne)\n return 0;\n if (dp[idx][mask] != -1)\n return dp[idx][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...
2
{ "code": "class Solution {\n vector<vector<int>> dp;\n int backtrack(vector<vector<int>>& arr, int i, int mask) {\n if (i >= arr.size()) return 0;\n if (dp[i][mask] != -1) return dp[i][mask];\n\n int acc = 0;\n if (!(mask & (1 << arr[i][1]))) { // take\n int nexti = i; // avoid picking same 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...
2
{ "code": "class Solution {\npublic:\n vector<pair<int,int>> arr;\n vector<vector<int>> dp;\n int solve(int i , int mask){\n if(i == arr.size())\n return 0;\n if(~dp[i][mask])\n return dp[i][mask];\n int ans = solve(i + 1, mask);\n for(int j = i; j < arr.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...
2
{ "code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n for (auto& a : grid) {\n sort(a.begin(), a.end(), greater<int>());\n }\n\n vector<pair<int, unordered_set<int>>> dp(1 << grid.size());\n\n for (int i = 0; i < dp.size(); i++) {\n for...
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 {\npublic:\n int res = 0;\n \n int maxScore(vector<vector<int>>& grid) {\n vector<vector<int>>collect(grid.size());\n map<int, vector<int>>num_index;\n for(int i = 0; i < grid.size(); i++){\n unordered_set<int>us;\n for(int j = 0; j < gri...
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 {\npublic:\n int FUNC(vector<vector<int>>& A) {\n int n = A.size();\n vector<set<int>> V(101);\n int h = 0;\n for (int p = 0; p < A.size(); p++) {\n for (int q = 0; q < A[p].size(); q++) {\n V[A[p][q]].insert(p);\n h = m...
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": "#include <vector>\n#include <unordered_map>\n#include <unordered_set>\n#include <algorithm>\n#include <string>\n\nclass Solution {\npublic:\n void sortRowsDescending(std::vector<std::vector<int>>& matrix) {\n for (auto& row : matrix) {\n std::sort(row.begin(), row.end(), std::greater<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...
2
{ "code": "class Solution {\npublic:\n int max_score(vector<vector<int>>& grid,int i,string &mp,vector<unordered_map<int, int> > &mp2, unordered_map<int, unordered_map<string, int>> &dp){\n int n=grid.size();\n if(i==n){\n return 0;\n }\n if(dp[i][mp]) return dp[i][mp];\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...
2
{ "code": "class Solution {\npublic:\n int max_score(vector<vector<int>>& grid,int i,string &mp,vector<unordered_map<int, int> > &mp2, unordered_map<int, unordered_map<string, int>> &dp){\n int n=grid.size();\n if(i==n){\n return 0;\n }\n if(dp[i][mp]) return dp[i][mp];\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...
2
{ "code": "class Solution {\npublic:\n map<pair<string,int>,int> mp;\n int f(vector<vector<int>> &grid,int val,int n,string &mask){\n if(val==0)return 0;\n if(mp.find({mask,val})!=mp.end())return mp[{mask,val}];\n int ans=0;\n bool flag=false;\n for(int i=0;i<n;i++){\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...
2
{ "code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<set<int>> val_rows(101);\n for(int i = 0; i < n; i++){\n for(int j = 0; j < m; j++){\n auto x = grid[i][j];\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...
2
{ "code": "class Solution {\npublic:\n void help(int id,vector<vector<int>>& a,unordered_map<int,int> &mp,unordered_set<int> &vis,int *ans)\n {\n int n=a.size();\n int m=a[0].size();\n if(id==n)\n {\n int sum=0;\n for(auto val: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...
2
{ "code": "vector<vector<vector<int>>>dp(102,vector<vector<int>>(102,vector<int>(1025,-1)));\nclass Solution {\npublic:\n \n int help(int i,vector<pair<int,int>>&v,int last,int mask){\n if(i==v.size())return 0;\n int ans=0;\n if(dp[i][last][mask]!=-1)return dp[i][last][mask];\n if(las...
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\n vector<vector<int>> dp;\n int solve(int ind , vector<vector<int>> &values,int mask){\n if(ind==values.size())return 0;\n\n if(dp[mask][ind] != -1)return dp[mask][ind];\n\n int ans = solve(ind+1,values,mask);\n\n if(!(mask & (1<<values[ind][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...
2
{ "code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n for (auto& row : grid) {\n set<int> unique_elements(row.begin(), row.end());\n row.assign(unique_elements.rbegin(), unique_elements.rend());\n }\n\n priority_queue<pair<int, vector<vector<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...
2
{ "code": "\nclass Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int n = grid.size();\n unordered_map<int, vector<int>> vals;\n\n // Organize grid values into the vals map\n for (int i = 0; i < n; ++i) {\n for (int h : grid[i]) {\n vals[h].p...
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": "// Focus on uniqueness in values first, then uniqueness in rows \nclass Solution {\npublic:\n int help(int i,int n,vector<int>&val,map<int,vector<int>>&mpp, map<pair<int,int>,int>&dp,int mask){\n if(i==n) return 0;\n if(dp.find({i,mask})!=dp.end()) return dp[{i,mask}];\n\n int an...
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 {\npublic:\n // int f(int row, vector<vector<int>>& grid, int m, int n, unordered_map<int,bool>& isPresent) {\n // if(row == m) {\n // return 0;\n // }\n // int ans = 0;\n // for(int i=row; i<m; i++) {\n // for(int j=0; j<n; j++) {\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...
2
{ "code": "\n\nclass Solution {\npublic:\n\n int rec(int ind,int mask, vector<vector<int>>&values,vector<vector<int>>&dp,int n){\n\n\n if(ind ==n)return 0;\n if(dp[ind][mask]!=-1){\n return dp[ind][mask];\n }\n int ans =0;\n int r = values[ind][1];\n if(((1<<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...
2
{ "code": "class Solution {\npublic:\n unordered_map<int, vector<int>> rowMap;\n vector<vector<int>>dp;\n int dfs(int max_num, int chosen_row)\n {\n if(max_num == 0)\n return 0;\n if(dp[max_num][chosen_row] != -1)\n return dp[max_num][chosen_row];\n \n int...
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 {\npublic:\n map<pair<int, int>, int> dp;\n int helper(vector<vector<int>> & vv, int index, int mask) {\n if (index < 0) {\n return 0;\n }\n if (dp.find(make_pair(index, mask)) != dp.end()) {\n return dp[make_pair(index, 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...
2
{ "code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n set<int> chosen;\n unordered_map<int, vector<int>> numRowMap;\n for (int i = 0; i < grid.size(); ++i)\n {\n for (int j = 0; j < grid[i].size(); ++j)\n numRowMap[grid[i][j]].empla...
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 {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n set<int> chosen;\n unordered_map<int, vector<int>> numRowMap;\n for (int i = 0; i < grid.size(); ++i)\n {\n for (int j = 0; j < grid[i].size(); ++j)\n numRowMap[grid[i][j]].empla...
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 {\npublic:\n int solve(int n, int idx, bitset<10> &b, vector<pair<int,int>> &v, vector<unordered_map<bitset<10>, int>> &dp){\n while(idx<n && b[v[idx].second]){\n idx++;\n }\n if(idx == n) return 0;\n if(dp[idx].find(b)!=dp[idx].end()) return dp[idx]...
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 #define long long ll\n int slove(int n, int i, vector<pair<int, vector<int>>>& v, int rowmask ,vector<vector<int>>&dp) {\n if (i == n)\n return 0;\n if(dp[i][rowmask]!=-1)\n return dp[i][rowmask];\n int take = 0, non_take = 0;\n non_t...
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 {\npublic:\n int solverec(int ele,int un,int &mx,unordered_map<int,vector<int>>& g,vector<vector<int>>&dp)\n {\n if(ele>mx)\n {\n return 0;\n }\n if(dp[ele][un]!=-1)\n {\n return dp[ele][un];\n }\n int ans=solverec(...
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 #define long long ll\n int slove(int &n, int i, vector<pair<int, vector<int>>>& v, int rowmask ,vector<vector<int>>&dp) {\n if (i == n)\n return 0;\n if(dp[i][rowmask]!=-1)\n return dp[i][rowmask];\n int take = 0, non_take = 0;\n non_...
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 {\nprivate:\n int withOrWithouYou(int n, int ind, vector<pair<int, vector<int>>>& v,\n int rowmask, vector<vector<int>>& dp) {\n if (ind == n) {\n return 0;\n }\n\n if (dp[ind][rowmask] != -1) {\n return dp[ind][rowmask];\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...
2
{ "code": "class Solution {\n #define long long ll\n int slove(int &n, int i, vector<pair<int, vector<int>>>& v, int rowmask ,vector<vector<int>>&dp) {\n if (i == n)\n return 0;\n if(dp[i][rowmask]!=-1)\n return dp[i][rowmask];\n int take = 0, non_take = 0;\n non_...
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 {\npublic:\n int dp[101][1025];\n int check(vector<vector<int>>&ans,int idx,int vis)\n {\n if(idx==ans.size())return 0;\n if(dp[idx][vis]!=-1)return dp[idx][vis];\n int a = ans[idx][0];\n int b = ans[idx][1];\n int sum = check(ans,idx+1,vis);\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...
2
{ "code": "class Solution {\npublic:\n int solve(int num,int mask,vector<vector<int>>&pos,vector<vector<int>>&dp)\n {\n if(num==0)\n {\n return 0;\n }\n if(dp[num][mask]!=-1)\n {\n return dp[num][mask];\n }\n vector<int>curr=pos[num];\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...
2
{ "code": "class Solution {\npublic:\n int solve(int num,int mask,vector<vector<int>>&pos,vector<vector<int>>&dp)\n {\n if(num==0)\n {\n return 0;\n }\n if(dp[num][mask]!=-1)\n {\n return dp[num][mask];\n }\n vector<int>curr=pos[num];\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...
2
{ "code": "class Solution {\npublic:\n\n vector<vector<int>> dp;\n vector<vector<int>> nums;\n\n int maxScore(vector<vector<int>>& grid) {\n\n int m=grid.size();int n=grid[0].size();\n\n dp.resize(101,vector<int>((1<<m),-1));\n nums.resize(101);\n\n for(int i=0;i<m;i++)\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...
2
{ "code": "class Solution {\npublic:\n int traverse(vector<vector<int>>& values, int index, int row_mask, int n, vector<unordered_map<int, int>>& dp) {\n if (index >= values.size() || __builtin_popcount(row_mask) == n) {\n // reached end of list or all rows are taken.\n return 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...
2
{ "code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n unordered_map<int, vector<int>> vals1;\n vector<pair<int, vector<int>>> vals;\n for (int i = 0; i < grid.size(); i++) {\n for (int j = 0; j < grid[0].size(); j++) {\n vals1[grid[i][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...
2
{ "code": "class Solution {\npublic:\n unordered_map<int, unordered_map<string, int>> dp;\n int solve(vector<vector<int>>& nums, int index, string str) {\n if(index >= nums.size()) {\n return 0;\n }\n if(dp.find(index) != dp.end() && dp[index].find(str) != dp[index].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...
2
{ "code": "class Solution {\npublic:\n int dp1(vector<vector<int>>& grid, vector<vector<int>>& memo, int i, int sum, int n, set<int>& s) {\n int m = grid[0].size();\n if (i >= n) {\n return 0;\n }\n if (memo[i][sum] != -1) {\n return memo[i][sum];\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...
2
{ "code": " \nclass 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 int notTake=0;int take=0;\n if ((1 << v[...
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 {\npublic:\n int max_score ( vector<vector<int>> & arr, int i, string &mp, vector<unordered_map<int, int> > &checker, unordered_map<int, unordered_map<string, int>> &dp){\n int n = arr.size();\n if(i == n)\n return 0;\n if(dp[i][mp])\n return dp[...
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 vector<vector<int>> wr;//which row\n map<pair<int,int>,int> dp;\n int recursion (int num,int &st){\n if(num==0)\n return 0;\n if(dp.find({num,st})!=dp.end()) return dp[{num,st}];\n int ans = 0;\n for(auto &r:wr[num]){\n if(st&(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...
2
{ "code": "class Solution {\n vector<vector<int>> wr;//which row\n map<pair<int,int>,int> dp;\n int recursion (int num,int &st){\n if(num==0)\n return 0;\n if(dp.find({num,st})!=dp.end()) return dp[{num,st}];\n int ans = 0;\n for(auto &r:wr[num]){\n if(st&(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...
2
{ "code": "class Solution {\n int solve(int idx, int mask, vector<pair<int, int>>& v, vector<vector<int>>& dp) {\n if (idx == v.size()) {\n return 0;\n } else if (dp[mask][idx] != -1) {\n return dp[mask][idx];\n }\n int res;\n int num = v[idx].first;\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...
2
{ "code": "class Solution {\npublic:\n vector<map<int,int>> dp;\n int solve(vector<vector<int>> &arr, int n, int mask){\n if(n==0)\n return 0;\n if(dp[n].find(mask)!=dp[n].end()){\n return dp[n][mask];\n }\n int ans = 0;\n for(int index:arr[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...
2
{ "code": "class Solution {\npublic:\n \n int lar = -1;\n map<pair<int,int >, int > dp;\n\n int calScore(int ind,vector< vector<int> > &g, int row){\n if(ind > lar)\n return 0;\n \n if(dp.find({ind,row}) != dp.end())\n return dp[{ind,row}];\n\n int score = calScor...
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 {\npublic:\n int recur(int ind,int vis,vector<vector<int>>& v,vector<vector<int>>& dp)\n {\n if(ind==v.size())\n return 0;\n if(dp[ind][vis]!=-1)\n return dp[ind][vis];\n int ans=recur(ind+1,vis,v,dp);\n if((vis&(1<<v[ind][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...
2
{ "code": "struct Cell {\n int value;\n int row;\n int col;\n\n Cell(int value, int row, int col) : value(value), row(row), col(col) {};\n\n bool operator>(const Cell& rhs) const { \n return value > rhs.value;\n } \n};\n\nclass Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) ...
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": "struct Cell {\n int value;\n int row;\n int col;\n\n Cell(int value, int row, int col) : value(value), row(row), col(col) {};\n\n bool operator>(const Cell& rhs) const { \n return value > rhs.value;\n } \n};\n\nclass Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) ...
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 {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size();\n array<vector<int>, 101> a;\n for (int i = 0; i < n; i++) {\n auto &v = grid[i];\n sort(v.begin(), v.end());\n for (int j = 0; j < m; 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...
2
{ "code": "class Solution {\npublic:\n int maxScore(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size();\n array<set<int>, 101> a;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n a[grid[i][j]].insert(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...
2
{ "code": "class Solution {\n map<pair<int, int>, int> dp;\n\n int findMax(int idx, int rowMask, vector<vector<int>>& values) {\n int n = values.size();\n if (idx == n) return 0;\n\n if (dp.find({idx, rowMask}) != dp.end()) return dp[{idx, rowMask}];\n\n int way1 = findMax(idx + 1, 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...
2
{ "code": "class Solution {\npublic:\n int dfs(int idx , vector<pair<int,int>> &v , int mask,map<pair<int,int>,int>&dp)\n {\n if(!mask)\n {\n return 0;\n }\n if(idx<0)\n {\n return 0;\n }\n if(dp.find({idx,mask})!=dp.end())\n {\n return dp[{idx,mask}];\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...
2
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\n\tmap<int, map<int, int>> dp;\n\tint f(map<int, vector<int>> &mp, int mask, int num, int n, int m, vector<vector<int>> &a) {\n\t\tif (num <= 0) return 0;\n\n\t\tif (dp.count(num) && dp[num].count(mask)) return dp[num][mask];\n\n\t\tint ans...
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 {\npublic:\n int dp[1<<10][105];\n int f(int mask,int ptr,map<int,set<int>>&mp,vector<int>&v){\n \n \n if(ptr==v.size())return 0;\n if(dp[mask][ptr]!=-1)return dp[mask][ptr];\n int ans=0;\n bool flag=false;\n int val=v[ptr];\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...
2
{ "code": "class Solution {\npublic:\n class Compare {\n public:\n bool operator () (const vector<int> & a, const vector<int> & b) const {\n int l = a.size();\n for (int i = 0; i < l; i++)\n if (a[i] != b[i])\n return a[i] < b[i];\n retur...