id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long dp[1000005];\n long long ans;\n long long solve(vector<vector<int>>& questions, int i) {\n if(i>=questions.size())\n return 0;\n if(dp[i]!=0) {\n return dp[i];\n }\n if(i>0)\n dp[i]=max(questions[i][...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long dp[1000005];\n long long ans;\n long long solve(vector<vector<int>>& questions, int i) {\n if(i>=questions.size())\n return 0;\n if(dp[i]!=0) {\n return dp[i];\n }\n if(i>0)\n dp[i]=max(questions[i][...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long dp[1000005];\n long long ans;\n long long solve(vector<vector<int>>& questions, int i) {\n if(i>=questions.size())\n return 0;\n if(dp[i]!=0) {\n return dp[i];\n }\n dp[i]=max(questions[i][0]+solve(questions,i+...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "\nclass Solution {\npublic:\n #define ll long long\n\n long long mostPoints(vector<vector<int>>& q) {\n int limit = 0;\n int n = q.size();\n for(int i=0;i<n;i++) limit = max(limit, q[i][1] + i);\n vector<ll> dp(limit+3);\n for(int i = n-1; i>=0 ; i--){\n ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long dp[1000002];\n long long solve(int ind,int n,vector<vector<int>>&ques){\n if(ind>=n)return 0;\n\n if(dp[ind]!=-1)return dp[ind];\n\n long long nottake=solve(ind+1,n,ques);\n long long take=ques[ind][0]+solve(ind+ques[ind][1]+1,n,ques);...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n \n vector<long long> v;\n\n long long func(vector<vector<int>>& questions,int n,int idx){\n if(idx>=n){return 0;}\n if(v[idx]!=-1){return v[idx];}\n long long iftake=func(questions,n,idx+questions[idx][1]+1)+questions[idx][0];\n long long not...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long mostPoints(vector<vector<int>>& questions) {\n long long dp[2000001] = {};\n for (int i = questions.size()-1; i >= 0; --i) {\n dp[i] = max(questions[i][0] + dp[questions[i][1]+i+1], dp[i+1]);\n }\n return dp[0];\n }\n};", ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long dp[1000005];\n long long ans;\n long long solve(vector<vector<int>>& questions, int i) {\n if(i>=questions.size())\n return 0;\n //cout<<i<<endl;\n if(dp[i]!=0) {\n return dp[i];\n }\n long long t1=solve...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long mostPoints(vector<vector<int>>& questions) {\n int n = questions.size();\n vector<long long> dp(n + 1, 0);\n for(int i = n-1; i > -1; --i){\n vector<int> q = questions[i];\n dp[i] = max(dp[i+1], q[0] + dp[min(n, i + q[1] + ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "typedef long long ll;\nll dp[100001]; // Make the size of dp large enough to handle the input size\nint n;\nvector<vector<int>> arr;\n\nll f(int i) {\n if (i >= n) return 0;\n if (dp[i] != -1) return dp[i];\n ll skip = f(i + 1);\n ll pick = arr[i][0] + f(i + arr[i][1] + 1);\n return dp[i] =...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long mostPoints(vector<vector<int>>& questions) {\n int n = questions.size();\n long long f[n];\n memset(f, 0, sizeof(f));\n function<long long(int)> dfs = [&](int i) -> long long {\n if (i >= n) {\n return 0;\n ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n #define ll long long\n ll dp[2000000] ;\n ll help(ll i, vector<vector<int>>& questions)\n {\n if(dp[i] != 0)\n {\n return dp[i];\n }\n if (i == questions.size() - 1)\n {\n return questions[i][0];\n }\n ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long mostPoints(vector<vector<int>>& questions) {\n vector<vector<long long>> dp(questions.size(),vector<long long> (2));\n long long MAX;\n for (int i=0;i<questions.size();i++)\n {\n dp[i][0]=questions[i][0];\n dp[...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long mostPoints(vector<vector<int>>& questions) {\n vector<vector<long long>> dp(questions.size(),vector<long long> (2));\n long long MAX;\n for (int i=0;i<questions.size();i++)\n {\n dp[i][0]=questions[i][0];\n dp[...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long mostPoints(vector<vector<int>>& questions) {\n vector<vector<long long>> dp(questions.size(),vector<long long> (2));\n long long MAX;\n for (int i=0;i<questions.size();i++)\n {\n dp[i][0]=questions[i][0];\n dp[...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long mostPoints(vector<vector<int>>& questions) {\n int n = questions.size();\n vector<vector<long long>> dp(n + 1, vector<long long>(2, 0)); // 2-column DP table\n\n for (int i = n - 1; i >= 0; --i) {\n // Max score if the current questio...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long mostPoints(vector<vector<int>>& questions) {\n \n long long n=questions.size();\n vector<vector<int>>v=questions;\n\n\n vector<long long>dp(n,0);\n dp[n-1]=v[n-1][0];\n for(long long i=n-2;i>=0;i--)\n {\n ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long mostPoints(vector<vector<int>>& questions) {\n \n long long n=questions.size();\n vector<vector<int>>v=questions;\n\n\n vector<long long>dp(n,0);\n dp[n-1]=v[n-1][0];\n for(long long i=n-2;i>=0;i--)\n {\n ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\nprivate:\n int n;\npublic:\n long long dfs(int i, vector<vector<int>>& quest, vector<long long>& dp){\n if(i>=n){\n return 0;\n }\n if(dp[i] != -1) return dp[i];\n return dp[i] = max({(long long)quest[i][0] + dfs(i + quest[i][1]+1, quest, dp), ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n long long dp[100001];\n vector<vector<int>> q;\n \n long long recurse(int i) {\n if (i >= q.size()) return 0;\n if (dp[i] != -1) return dp[i];\n dp[i] = max(q[i][0] + recurse(q[i][1]+i+1), recurse(i+1));\n return dp[i];\n }\n \n l...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>>v;\nint n;\nlong long dp[100100];\nlong long f(int i){\n if(i>=n) return 0;\n if(dp[i]!=-1) return dp[i];\n long long ans=f(i+1);\n ans=max(ans,v[i][0]+f(i+v[i][1]+1));\n return dp[i]=ans;\n}\n long long mostPoints(vector<vector<int>>& q) {\n ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n vector<vector<int>>q;\n ll dp[100001];\n ll rec(int l){\n if(l>=q.size())return 0;\n auto &ans=dp[l];\n if(ans!=-1)return ans;\n ans=max(rec(l+1),rec(l+q[l][1]+1)+q[l][0]);\n return ans;\n }\n long long most...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n vector<vector<int>>q;\n int n;\n ll dp[100005];\n \n ll solve(int idx){\n if(idx>=n)\n return 0*1ll;\n \n if(dp[idx] != -1)\n return dp[idx];\n \n ll case1 = solve(idx+q[idx][1]+1)+q[id...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n vector<long long int> dp;\n int size;\n vector<vector<int>> questions;\n long long int points(int i)\n {\n if(i >= size)\n return 0;\n if(dp[i] != -1)\n return dp[i];\n long long int answer;\n long long int skip = ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\nprivate:\n vector<long long> memo;\n vector<vector<int>> questions;\n long long dp (int i){\n if (i >= questions.size()){\n return 0;\n }\n if (memo[i] != 0){\n return memo[i];\n }\n int j = questions[i][1] + i + 1;\n ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>>questions;\n long long mostPoints(vector<vector<int>>& questions) {\n this->questions = questions;\n vector<long long> memo(questions.size(),0);\n return dp(0,memo);\n }\n\n long dp(int i, vector<long long>& memo)\n {\n i...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution \n{\npublic:\n\n \n\n vector<vector<int>> questions;\n vector<long long> memo;\n \n\n long long mostPoints(vector<vector<int>>& questions) \n {\n this->questions = questions; // Initialize the questions matrix\n memo = vector<long long>(questions.size(), 0);\n ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n vector<long long> memo;\n vector<vector<int>> questions;\n long long mostPoints(vector<vector<int>>& questions) {\n // memo = vector(questions.size(), -1);\n memo = vector<long long>(questions.size(), -1);\n this->questions = questions;\n ret...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> questions;\n long long mostPoints(vector<vector<int>>& questions) {\n this->questions = questions;\n vector<long long> memo(questions.size(), 0);\n return dp(0, memo);\n }\n long long dp(int i, vector<long long> &memo) {\n ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> q;\n vector<long long> memo;\n long long mostPoints(vector<vector<int>>& questions) {\n q = questions;\n memo.assign(q.size(), -1);\n return f(0);\n }\n long long f(int i){\n if(i >= q.size())\n return 0;\...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n vector<long long> dp;\n int n;\n vector<vector<int>> qs;\n long long rec (int x)\n {\n if (x >= n)\n return 0;\n if (dp[x] != -1)\n return dp[x];\n \n long long o1 = rec(x+1);\n ...
2,262
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p> <p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <cod...
3
{ "code": "class Solution {\npublic:\n\n vector<vector<int> > q;\n vector<long > memo; \n long long mostPoints(vector<vector<int>>& questions) {\n this->q= questions; \n\n vector<long> memo(questions.size(),-1);\n this->memo = memo; \n\n if(q.size()<= 0){\n return 0 ; \...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
0
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr); cout.tie(nullptr);\n long long low=1;\n long long high=0;\n for(auto it:batteries) high+=it;\n high=high/n;\n // long...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
0
{ "code": "typedef long long ll;\nclass Solution {\n bool isPossible(ll mid,int n,vector<int>& b){\n ll sum = 0;\n ll targetedSum = n*mid;\n for(int i = 0;i<b.size();i++){\n sum += min((ll)b[i],mid);\n if(sum>=targetedSum)return true;\n }\n return false;\n ...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
0
{ "code": "class Solution {\npublic:\nbool f(long long mid,int n, vector<int>& arr){\n long long cnt = 0;\n for(auto it: arr){\n cnt += min(mid,(long long)it);\n }\n return cnt >= (long long)n*mid;\n}\n long long maxRunTime(int n, vector<int>& arr) {\n long long low = 0;\n long...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
0
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n long long left = 1, right = accumulate(batteries.begin(), batteries.end(), 0LL) / n;\n while (left < right) {\n long long mid = (left + right + 1) / 2;\n long long total = 0;\n ...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
0
{ "code": "class Solution {\npublic:\n typedef long long ll;\n\n bool possible(vector<int>&batt,ll mid,int n){\n ll target = n* mid;\n ll sum=0;\n\n for(int i=0;i<batt.size();i++){\n target -= min((ll)batt[i],mid);\n if(target <= 0)return true;\n }\n retu...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
1
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n int m=batteries.size();\n int min_power=*min_element(batteries.begin(), batteries.end());\n if (m==n) return min_power;\n long long left=min_power;\n long long right=accumulate(batterie...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
1
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n int m=batteries.size();\n int min_power=*min_element(batteries.begin(), batteries.end());\n if (m==n) return min_power;\n long long left=min_power;\n long long right=accumulate(batterie...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
2
{ "code": "class Solution {\npublic:\n bool check(long long ans,vector<int>&bat,int n)\n {\n long long sum=0;\n long long target=ans*n;\n\n for(int i=0;i<bat.size();i++)\n {\n // target-=min((long long)bat[i],ans);\n sum+=min((long long)bat[i],ans);\n\n ...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
2
{ "code": "// Greed Beats 100% time and memory \n\nclass Solution {\npublic:\n#define ll long long\n ll maxRunTime(int n, vector<int>& batteries) {\n ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); \n nth_element(batteries.begin(), batteries.end() - n, batteries.end());\n s...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
2
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); \n sort(batteries.begin(), batteries.end());\n long long s = accumulate(batteries.begin(), batteries.end() - n + 1, 0LL);\n in...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
2
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n std::nth_element(batteries.begin(), batteries.end() - n, batteries.end());\n std::sort(batteries.end() - n + 1, batteries.end());\n int64_t power = std::accumulate(batteries.begin(), batteries.end() - n + 1, 0LL);...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
2
{ "code": "class Solution {\npublic:\n using ll=long long;\n bool find(ll mid,int n,vector<int> &b){\n ll sum=0;\n for(auto it: b){\n sum+=(min(mid,it*1LL));\n }\n return (sum>=(n*1LL*mid));\n }\n long long maxRunTime(int n, vector<int>& b) {\n ll ans=0;\n ...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
2
{ "code": "using ll = long long;\nclass Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n sort(begin(batteries),end(batteries));\n int N=batteries.size();\n ll s=0;\n for(int i=0;i<N-n;i++)s+=batteries[i];\n cout<<s<<endl;\n int prevCount=0;\n ...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
2
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n long long sum = accumulate(batteries.begin(), batteries.end(), 0LL);\n int size = batteries.size();\n sort(batteries.begin(), batteries.end());\n int i = 0;\n while(i<size && sum/(n-i) ...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n #define ll long long\n long long maxRunTime(int n, vector<int>& batteries) {\n sort(batteries.begin(),batteries.end());\n ll extra=0;\n int N=batteries.size();\n for(int i=0;i<N-n;i++) extra+=batteries[i];\n // vector<ll>live;\n //...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& bat) {\n int m = bat.size();\n sort(bat.begin(),bat.end(),greater<int>());\n vector<int>v(n);\n if(m==n)return *min_element(bat.begin(),bat.end());\n long long mini = *min_element(bat.begin(),bat.end(...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n // Sort the batteries in ascending order.\n sort(batteries.begin(), batteries.end());\n \n // Calculate the sum of all extra batteries (those not initially allocated to the n devices).\n ...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n vector<int>bateria;\n int n;\n bool check(long long mid){\n long long sum=0;\n for(auto it: bateria){\n sum+=min(mid,(long long)it);\n }\n if(sum>=mid*n)return true;\n return false;\n }\n long long maxRunTime(int n1, ve...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\n using ll = long long;\n\npublic:\n auto valid(ll x, int tam, int n, vector<int> &batteries) {\n ll s = 0;\n for (int i = 0; i < tam; ++i)\n if (batteries[i] >= x)\n s += x;\n else\n s += batteries[i];\n \n ...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n long long s = *min_element(batteries.begin(),batteries.end()), e = 0;\n sort(batteries.begin(),batteries.end(),greater<int>());\n vector<int>v(n),a(n);\n if( n == batteries.size()) return s;\n...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "#include <vector>\n#include <queue>\n#include <numeric>\n\nusing namespace std;\n\nclass Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n priority_queue<int> pq {batteries.begin(), batteries.end()};\n\n long long sum = accumulate(batteries.begin(), batteries.en...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& b) {\n sort(b.rbegin(),b.rend());\n long long l = 0, r = 1e15,ans, sum = 0;\n for(int ch : b) sum += ch;\n\n while(l <= r) {\n long long mid = l + (r-l)/2ll;\n long long tot = n,e = sum...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n long long ans = accumulate(batteries.begin(), batteries.end(), 0LL);\n priority_queue<int> maxHeap(batteries.begin(), batteries.end());\n while(!maxHeap.empty() && maxHeap.top() > ans/n)\n {\n...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n #define ll long long\n long long maxRunTime(int n, vector<int>& batteries) {\n sort(batteries.begin(),batteries.end());\n ll extra=0;\n int N=batteries.size();\n for(int i=0;i<N-n;i++) extra+=batteries[i];\n vector<ll>live;\n for(i...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& b) { \n sort(b.begin(),b.end());\n long long count = b[b.size()-n];\n long long extra = accumulate(b.begin(),b.begin()+b.size()-n,0ll);\n vector<long long> diff;\n for(int i = b.size()-n; i<b.size()-1...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n if(batteries.size()==n){\n return *min_element(batteries.begin(),batteries.end());\n }\n sort(batteries.begin(),batteries.end());\n int sz = batteries.size();\n long long sum...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n sort(batteries.rbegin(),batteries.rend());\n vector<int>cmp;\n int i=0;\n long long sum=0;\n for(;i<n;i++){\n cmp.push_back(batteries[i]);\n } \n for(;i<batteri...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n long long drain_batteries(long long n, vector<long long>& batteries, long long extraBattery) {\n long long divideCount = 0;\n auto bottleneck = batteries.begin() + n - 1;\n for (auto it = batteries.begin() + n - 1; it != batteries.begin(); --it) {\n ...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n if(batteries.size()==n){\n return *min_element(batteries.begin(),batteries.end());\n }\n sort(batteries.rbegin(),batteries.rend());\n int sz = batteries.size();\n long long s...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n long long maxRunTime(int n, vector<int>& batteries) {\n const int m = batteries.size();\n \n long l = 1, r = accumulate(batteries.begin(), batteries.end(), 0L) / n;\n while (l < r) {\n const long m = r - (r - l) / 2;\n if (sat...
2,263
<p>You have <code>n</code> computers. You are given the integer <code>n</code> and a <strong>0-indexed</strong> integer array <code>batteries</code> where the <code>i<sup>th</sup></code> battery can <strong>run</strong> a computer for <code>batteries[i]</code> minutes. You are interested in running <strong>all</strong>...
3
{ "code": "class Solution {\npublic:\n typedef long long ll;\n bool isPossible(vector<int> batteries, int N, ll& midTime){\n // total time required by N computers if the battery lifespan is midTime\n ll targetMinutes = N * midTime;\n ll sum = 0;\n\n for(int i = 0; i < batteries.size(...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
0
{ "code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n sort(begin(envelopes), end(envelopes), [](auto& e1, auto& e2) {\n if (e1[0] != e2[0]) {\n return e1[0] < e2[0];\n }\n\n return e1[1] > e2[1];\n });\n\n in...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
0
{ "code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n\n const int n = envelopes.size();\n\n // Sort by width to forget about it and just solve \n // 300. Longest Increasing Subsequence for heights.\n // The main trick here is to sort descending by h...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
2
{ "code": "class Solution {\npublic:\n static bool cmp(vector<int> &a,vector<int> &b){\n if(a[0]==b[0]){\n return a[1]>b[1];\n }\n return a[0]<b[0];\n }\n \n int solve_binary_search(vector<int> nums,int n){\n if(n==0){\n return 0;\n }\n\n vector<int> ans;\n ...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
2
{ "code": "\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define maxn 100010\n\n#define pii pair<int,int>\n#define mp make_pair\n#define F first\n#define S second\n\n\n\n\nclass Solution {\npublic:\n pii P[maxn];\n\n int n;\n int dp[maxn];\n int ST[10*maxn+10];\n\n void upd (int N, int L, int R...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
2
{ "code": "// Hay\nvoid printArr(const vector<int> & arr){\n for(int i = 0 ; i < arr.size() ; i ++) cout<<arr[i]<<\" \";\n cout<<endl;\n}\nvoid printArr(const vector<vector<int>> & arr){\n for(int i = 0 ; i < arr.size() ; i ++) printArr(arr[i]);\n}\nbool myfunc(const vector<int> & a, const vector<int> & b){\...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
2
{ "code": "class Solution {\n private: \n bool static compare(pair<int,int>&a, pair<int,int>&b)\n {\n if(a.first!=b.first)\n return (a.first<b.first);\n\n return (a.second>b.second);\n }\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n int n=envelopes.size();\...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n\nint lis(vector<int> arr){\n vector<int> ans;\n for(int i=0;i<arr.size();i++){\n if(ans.size()==0||ans[ans.size()-1]<arr[i]) ans.push_back(arr[i]);\n else{\n auto id=lower_bound(ans.begin(),ans.end(),arr[i])-ans.begin();\n ans[id]=arr[i]...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\n\nprivate:\n int searchLesser(map<int, int> &m, int i) {\n auto it = m.lower_bound(i);\n if (it == begin(m)) return 0;\n return (--it) -> second;\n }\n\n int lis(vector<vector<int>> &envelopes) {\n map<int, int> m;\n vector<int> dp(envelopes.siz...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n static bool cmp(vector<int>&v1,vector<int>&v2){\n if(v1[0]==v2[0]){\n return v1[1]>v2[1];\n }\n return v1[0]<v2[0];\n }\n int maxEnvelopes(vector<vector<int>>&nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end(),cmp);...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\nstatic bool sorting(vector<int>& a, vector<int>& b){\n if(a[0]!=b[0])return a[0]<b[0];\n else return a[1]>b[1];\n}\n int maxEnvelopes(vector<vector<int>>& ev) {\n sort(ev.begin(), ev.end(),sorting);\n \n vector<int>ans;\n for(auto it:ev)cout<<...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& e) {\n vector<pair<int, int>> envelopes(e.size());\n for(int i=0;i<e.size();i++)envelopes[i] = {e[i][0], e[i][1]};\n sort(envelopes.begin(), envelopes.end(), [](pair<int, int>& a, pair<int, int>& b){\n if(a...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n //sort(envelopes.begin(), envelopes.end());\n map<int, vector<int>> mp;\n for(vector<int>& envelope: envelopes){\n mp[envelope[0]].push_back(envelope[1]);\n }\n envelopes.clear(...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "#define ff first\n#define ss second\n#define MP make_pair\nclass FW { \n public: \n int n; \n vector<vector<pair<int, int>>> root; \n FW(int n) { \n this->n = n; \n root.resize(n + 1, vector<pair<int, int>>(2, {-1, -1}));\n }\n\n void update(int id, int x, int val) { ...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n // sort(envelopes.begin(),envelops.end());\n vector <pair<int,int>> b(envelopes.size());\n for(int i=0;i<envelopes.size();i++)\n {\n b[i].first=envelopes[i][0];\n b[i].secon...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n bool check(int indx,vector<map<int,int>> &level_row_thrushold_col,vector<int> & a){\n // cout<<indx<<\" \";\n auto v = level_row_thrushold_col[indx].upper_bound(a[0]) ;\n if(v==level_row_thrushold_col[indx].begin())return false ;\n else {\n ...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n const int N = envelopes.size();\n int mx = 0;\n map<int,set<int,greater<>>> env;\n for (auto & vec: envelopes) {\n env[vec[0]].insert(vec[1]);\n }\n vector<int> LIS(N+1);...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n map<int,vector<int>>m;\n for(auto it:envelopes){\n m[it[0]].push_back(it[1]);\n }\n\n vector<int>v;\n\n for(auto it:m){\n sort(it.second.rbegin(),it.second.rend());\n...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n\n int solve(vector<int> store, int n){\n if(n == 0) return 0;\nvector<int> temp;\ntemp.push_back(store[0]);\n\nfor(int i = 1;i < n;i++){\n if(store[i] > temp.back()){\n temp.push_back(store[i]);\n }\n else{\n int index = lower_bound(temp.begin(),...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\n \nprivate:\n static bool byWidthFn(vector<int>& wh1, vector<int>& wh2) {\n if (wh1[0] == wh2[0]) return wh1[1] < wh2[1];\n return wh1[0] < wh2[0];\n }\n \nconst bool debug = false;\n \npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n /...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n \n int maxEnvelopes(vector<vector<int>>& mat) {\n vector<vector<int>>grid(mat);\n int n=mat.size();\n for(int i=0;i<n;i++)\n grid[i][1]=-grid[i][1];\n sort(grid.begin(),grid.end());\n set<int>s;\n vector<int>a;\n ...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\n class seg {\n vector<int> t;\n const int n;\n public:\n seg(int n) : n(n) {\n t = vector<int>(n << 1, 0);\n }\n\n int query(int l, int r) {\n int res = 0;\n for (l += n, r += n; l < r; l>>=1, r>>=1) {\n ...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\n class seg {\n vector<int> t;\n const int n;\n public:\n seg(int n) : n(n) {\n t = vector<int>(n << 1, 0);\n }\n\n int query(int l, int r) {\n int res = 0;\n for (l += n, r += n; l < r; l>>=1, r>>=1) {\n ...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n static bool mycomp(vector<int>& a, vector<int>& b){\n if(a[0]==b[0]){\n return a[1]>b[1];\n }\n return a<b;\n }\n bool check(vector<int> curr, vector<int> prev){\n if(curr[0]>prev[0] && curr[1]>prev[1]){\n return true;\n...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n static bool cmp(vector<int>& v1, vector<int>& v2){\n if(v1[0]<v2[0] || (v1[0]==v2[0] && v1[1]>v2[1])){\n return true;\n }\n return false;\n }\n\n void binary_search_addition(vector<vector<int>>& ans, int start, int end, vector<int> envelo...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n static bool cmp(vector<int>& v1, vector<int>& v2){\n if(v1[0]<v2[0] || (v1[0]==v2[0] && v1[1]>v2[1])){\n return true;\n }\n return false;\n }\n\n void binary_search_addition(vector<vector<int>>& ans, int start, int end, vector<int> envelo...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n vector<int>segTree;\n int BASE;\n void update(int index, int val){\n index += BASE;\n segTree[index] = val;\n index >>= 1;\n while(index > 0) {\n segTree[index] = max(segTree[index<<1], segTree[(index<<1)|1]);\n index >>...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n int getMax(int idx, int si, int st, int qi, int qt, vector<int>& arr){\n if(si>=qi && st<=qt)\n return arr[idx];\n if(si>qt || st<qi)\n return 0;\n int mid=(si+st)/2;\n return max(getMax(2*idx+1, si, mid, qi,qt, arr), getMax(2...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n int getMax(int idx, int si, int st, int qi, int qt, vector<int>& arr){\n if(si>=qi && st<=qt)\n return arr[idx];\n if(si>qt || st<qi)\n return 0;\n int mid=(si+st)/2;\n return max(getMax(2*idx+1, si, mid, qi,qt, arr), getMax(2...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n\n static bool compare(vector<int>&a,vector<int>&b){\n if(a[0]==b[0]){\n if(a[1]<b[1]) return false;\n return true;\n }\n if(a[0]<b[0]) return true;\n return false;\n }\n\n class segmentTree{\n public:\n vector<int...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "template<typename T>\nclass SegTree\n{\n int n;\n vector<T> tree;\n public:\n\n SegTree(int sz)\n {\n tree.resize(4*sz);\n }\n\n int query(int id, int segl, int segr, int l, int r)\n {\n if(l> segr || r < segl)\n {\n return 0;\n }\n if(s...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n int binarySearch(vector<int> ans, int target){\n int s=0 , e= ans.size();\n while(s<e){\n int mid = s + (e-s)/2;\n if(ans[mid] == target) return mid;\n else if(ans[mid]>target) e= mid;\n else s= mid+1;\n }\n ...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\nstatic bool comp(vector<int> &a, vector<int> &b){\n if(a[0]==b[0]){\n return a[1]>b[1];\n }\n return a[0]<b[0];\n }\n\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n sort(envelopes.begin(), envelopes.end(), comp);\n int n...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\npublic:\n\nint lis(vector<int> value,int l, int r, int val){\n while(l<r){\n int m = l+(r-l)/2;\n if(value[m]>=val) r=m;\n else l = m+1;\n }\n return r;\n}\nstatic bool comp (vector<int>&a, vector<int>& b){\n if(a[0]==b[0]){\n return a[1]>b[1];\n ...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "class Solution {\n private:\n \n\n auto lower_bound(vector<int> monostack, int val) {\n int lo = 0, hi = monostack.size() - 1;\n while (lo < hi) {\n auto mi = lo + ((hi - lo) >> 1);\n if (monostack[mi] < val) lo = mi + 1;\n else hi = mi;\n }\n...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "struct envelope{\n int width;\n int height;\n};\nclass Solution {\npublic:\n int findCeil(vector<int>heights,int height){\n int l =0,r= heights.size()-1;\n while(l<r){\n int mid =l+(r-l)/2;\n if(heights[mid]>=height){\n r= mid;\n }\n ...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "struct envelope{\n int width;\n int height;\n};\nclass Solution {\npublic:\n int findCeil(vector<int>heights,int height){\n int l =0,r= heights.size()-1;\n while(l<r){\n int mid =l+(r-l)/2;\n if(heights[mid]>=height){\n r= mid;\n }\n ...
354
<p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&#39;s...
3
{ "code": "struct envelope{\n int width;\n int height;\n};\nclass Solution {\npublic:\n int findCeil(vector<int>heights,int height){\n int l =0,r= heights.size()-1;\n while(l<r){\n int mid =l+(r-l)/2;\n if(heights[mid]>=height){\n r= mid;\n }\n ...