id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& a, int k) {\n // important idea : min decreases/max increases when size of subarray increases\n // nxt[x] : first idx to the right of \"k\" s.t. a[idx] < x\n // prv[x] : first idx to the left of \"k\" s.t. a[idx] < x\n\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "#define FOR(i, n) for(int i=0; i<n; i++)\n#define IFOR(i, a, b) for(int i=a; i<b; i++)\n\nclass Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n int ans = nums[k];\n // Itertaion 1\n stack<int> st1;\n FOR(i, k+1) st1.push(i);\... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size(),res=0;\n vector<int> range(n);\n\n stack<int> st;\n\n for(int i=0;i<n;i++){\n while(!st.empty() && nums[i]<nums[st.top()]){\n int t = st.top();\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> l(n);\n stack<int> s;\n for (int i = 0; i < n; i++) {\n while (!s.empty() && (nums[s.top()] >= nums[i])) s.pop();\n l[i] = s.empty() ? -1 : s.to... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n stack<int>s;\n vector<int>nxt(n);\n for(int i=0;i<n;++i){\n while(!s.empty() && nums[s.top()]>nums[i]){\n nxt[s.top()]=i;\n s.pop();\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n vector<int>pref(k+1 , 0) , suff ; \n pref[k] = nums[k] ;\n for(int i=k-1 ; i>=0 ;i--){\n pref[i] = (min(pref[i+1] , nums[i])) ;\n }\n suff.push_back(nums[k]) ;\n \n for... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int ans = nums[k];\n int i = 0;\n int n = nums.size();\n int j = n - 1;\n\n vector<int> left(n, INT_MAX), right(n, INT_MAX);\n left[k] = nums[k];\n right[k] = nums[k];\n for... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size(),maxi=0;\n vector<int> pre(n),suff(n);\n int mini=nums[k];\n for(int i=k;i>=0;i--){\n mini=min(mini,nums[i]);\n pre[i]=mini;\n }\n mini=nums[k];\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& A, int k) {\n const int N = A.size();\n \n // monostack\n vector<int> rs(N);\n for (int i = N - 1; i >= 0; i --){\n int n = i + 1;\n\n // strictly greater\n while (n < N && A[n] ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n \n // Arrays to store the left and right boundaries for each element\n vector<int> left(n), right(n);\n \n // Initialize left boundaries\n for (int i = 0; i ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& a, int k) {\n int n=a.size();\n vector<int> st;\n st.push_back(-1);\n int ans=0;\n vector<int> right(n+1);\n for(int i=n-1;i>=0;i--){\n while(st.back()!=-1 and a[st.back()]>=a[i]){\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> left(n, -1);\n vector<int> stack;\n \n for (int i = n - 1; i >= 0; i--) {\n while (!stack.empty() && nums[stack.back()] > nums[i]) {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> left(n, -1);\n vector<int> stack;\n \n for (int i = n - 1; i >= 0; i--) {\n while (!stack.empty() && nums[stack.back()] > nums[i]) {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> left(n, -1);\n vector<int> stack;\n \n for (int i = n - 1; i >= 0; i--) {\n while (!stack.empty() && nums[stack.back()] > nums[i]) {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> left(n, -1);\n vector<int> stack;\n \n for (int i = n - 1; i >= 0; i--) {\n while (!stack.empty() && nums[stack.back()] > nums[i]) {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\nSolution(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n}\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n stack<int> sl, sr;\n vector<int> left(n,-1), right(n,n);\n for(int i=0; i<n; i++){\n... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\nSolution(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n}\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n stack<int> sl, sr;\n vector<int> left(n,-1), right(n,n);\n for(int i=0; i<n; i++){\n... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n Solution(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n }\n \n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> left(n), right(n);\n\n // Combine left and right bo... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\nSolution(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n}\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n stack<int> sl, sr;\n vector<int> left(n,-1), right(n,n);\n for(int i=0; i<n; i++){\n... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int> l(n),r(n);\n stack<int> st;\n for(int i=0;i<n;i++){\n while(!st.empty() && nums[i]<=nums[st.top()]){\n st.pop();\n }\n l... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "#include <vector>\n#include <stack>\n#include <algorithm>\n#include <climits>\n#include <iostream>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> nsl(n + 1, n); \n vector<int> psl(n + 1, -1); \... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n stack<int>st;\n int n = nums.size();\n vector<int>left(n,-1), right(n,n);\n\n for(int i = 0 ; i < n ; i++){\n while(!st.empty() && nums[st.top()] >= nums[i]) {\n st.... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n stack<int> s,ss;\n vector<int> nse(n,n),pse(n,-1);\n for(int i=0;i<n;i++){\n while(!s.empty() && nums[i]<=nums[s.top()]){\n nse[s.top()]=i;\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n\n int N = nums.size();\n vector<int> left_smallest_num(N);\n vector<int> right_smallest_num(N);\n\n stack<int> l_stc{};\n stack<int> r_stc{};\n\n for (int i = 0; i < N; i++) {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\nvector<int>nse(vector<int >&nums){\nstack<int>st;\nint i;\nint n=nums.size();\nvector<int>ans(n);\nfor(i=n-1;i>=0;i--){\n while(!st.empty()&&nums[st.top()]>=nums[i]){\n st.pop();\n }\n if(st.empty()){\nans[i]=n-1;\n }\n else{\n ans[i]=st.top()-1;\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n vector<int> leftSmaller(vector<int>& arr){\n int n = arr.size();\n stack<int> st;\n vector<int> ans(n);\n\n for(int i = 0; i < n; i++){\n while(!st.empty() && arr[i] < arr[st.top()]){\n st.pop();\n }\n\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\nprivate:\n void stack_op(int i, stack<int> &st, vector<int> &heights, vector<int> &nse){\n if (st.empty()){\n st.push(i);\n }\n else{\n while (!st.empty() && heights[st.top()] > heights[i]){\n nse[st.top()] = i;\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> li(n),ri(n);\n\n vector<int> st(n);\n int stp = 0;\n li[0] = -1;\n st[stp] = 0;\n int i = 1;\n while(stp != -1 && i < n){\n whil... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int ans = solve(nums, k);\n reverse(nums.begin(), nums.end());\n return max(ans, solve(nums, nums.size() - k - 1));\n }\n \n int solve(vector<int>& nums, int k) {\n int n = nums.size();\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int ans = solve(nums, k);\n reverse(nums.begin(), nums.end());\n return max(ans, solve(nums, nums.size() - k - 1));\n }\n \n int solve(vector<int>& nums, int k) {\n int n = nums.size();\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\n class SegmentTree {\n vector<int> tree;\n int n;\n\n // Build the segment tree from the given array\n void buildTree(vector<int>& arr, int start, int end, int node) {\n if (start == end) {\n tree[node] = arr[start];\n } ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "#define ll long long\n#define pb push_back\nclass Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n ll n = nums.size();\n vector<ll>prev(n);\n vector<ll>next(n);\n prev[k]=nums[k];\n next[k]=nums[k];\n for(ll i=k+1;i<n;i++){\n prev[... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& a, int k) {\n int n = a.size();\n map<int,int> mp2;map<int,int> mp1;\n int mi = a[k],ans=a[k];mp2[mi]=k;\n if(n==1){return ans;}\n vector<int> vmi(n,a[k]);\n for(int i=k;i<n;i++){\n mi = min(mi... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n\n\n vector<int> v1;\n vector<int> v2;\n\n int find(int target,int k,int n){\n\n // find elements from k to 0 for which target is min\n // find elements from k+1 to n for which target is min\n\n \n\n int elemt1 = k+1 - (lower_bound(v1.begin()... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n int ans=0;\n stack<int> st;\n stack<int> st_r;\n vector<int> NSL;\n vector<int> NSR(n,0);\n for(int i=0;i<n;i++){\n while(!st.empty() && nums[i]<=nu... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>left;\n vector<int>right(n);\n stack<int>st;\n for(int i=0;i<n;i++){\n while(!st.empty()&&nums[st.top()]>=nums[i]) st.pop();\n if(st.empty()... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>left;\n vector<int>right(n);\n stack<int>st;\n for(int i=0;i<n;i++){\n while(!st.empty()&&nums[st.top()]>=nums[i]) st.pop();\n if(st.empty()... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n int ans=0;\n stack<int> st;\n stack<int> st_r;\n vector<int> NSL;\n vector<int> NSR(n,0);\n for(int i=0;i<n;i++){\n while(!st.empty() && nums[i]<=nu... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n\n stack<int>s;\n vector<long long>left(n,0),right(n,0);\n for(int i=n-1;i>=0;i--){\n while(s.size() && nums[s.top()]>=nums[i]){\n s.pop();\n }\... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n struct subarray {\n size_t l;\n size_t r;\n };\n\n int maximumScore(vector<int>& nums, int k) {\n stack<size_t> st; // <num, idx>\n vector<subarray> mp(nums.size()); // idx -> {l, r}\n\n for (size_t i = 0; i < nums.size(); i++) {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n\n stack<int>s;\n vector<long long>left(n,0),right(n,0);\n for(int i=n-1;i>=0;i--){\n while(s.size() && nums[s.top()]>=nums[i]){\n s.pop();\n }\... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n int ans = 0;\n\n vector<int> nsr(n), nsl(n);\n \n stack<int> st;\n for (int i = 0; i < n; ++i) {\n while (!st.empty() && nums[st.top()] >= nums[i]) {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 3 | {
"code": "class Solution {\npublic:\n \nvector<int>Nearest_Smallest_left(vector<int>v){\n stack<int>st;\n int n = v.size();\n vector<int>left_min(n);\n left_min[0] = -1;\n st.push(0);\n for(int i=1; i<n; i++){\n while(st.size() && v[st.top()] >= v[i]) st.pop();\n if(st.empty()) left... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "// /**\n// * Definition for a binary tree node.\n// * struct TreeNode {\n// * int val;\n// * TreeNode *left;\n// * TreeNode *right;\n// * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n// * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n// * TreeNode(int... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int key) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeN... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
450 | <p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return <em>the <strong>root node reference</strong> (possibly updated) of the BST</em>.</p>
<p>Basically, the deletion can be divided into two stages:</p>
<ol>
<li>Search for a node to remove.</li>
<li>If the node is f... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 0 | {
"code": "class Solution {\npublic:\n int minMoves(vector<int>& nums) {\n int n = nums.size();\n int count = 0;\n int min = nums[0];\n\n for (int i = 0; i < n; i++) {\n if (nums[i] < min) {\n min = nums[i];\n }\n }\n for (int i = 0; i ... |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 0 | {
"code": "class Solution {\npublic:\n int minMoves(vector<int>& nums) {\n if (nums.empty()) return 0;\n \n // Find the minimum element\n int minElement = *min_element(nums.begin(), nums.end());\n \n // Calculate the sum of differences from min element\n int moves = ... |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 0 | {
"code": "\tclass Solution{\n\tpublic://Remember--whenever someone trash talks your country, state, city, home, community, etc--their feet are usually telling you that they're a liar.\n\t\tint minMoves(vector<int>& nums){\n\t\t\tint m=INT_MAX;\n\t\t\tfor(int n:nums) m=min(m,n);\n\t\t\tint ans=0;\n\t\t\tfor(int n:num... |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 0 | {
"code": "class Solution {\npublic:\n int minMoves(vector<int>& nums) {\n int mini = INT_MAX;\n for (const auto& num : nums) mini = min(mini, num);\n int moves = 0;\n for (const auto& num : nums) moves += (num - mini);\n return moves;\n }\n};",
"memory": "30900"
} |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 0 | {
"code": "class Solution {\npublic:\n int minMoves(vector<int>& nums) {\n int val = *std::min_element(nums.cbegin(), nums.cend());\n int ans = 0;\n for(const auto i : nums) {\n ans += i - val;\n }\n return ans;\n }\n};",
"memory": "30900"
} |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 0 | {
"code": "\tclass Solution{\n\tpublic://Remember--whenever someone trash talks your country, state, city, home, community, etc--their feet are usually telling you that they're a liar.\n\t\tint minMoves(vector<int>& nums){\n\t\t\tint m=INT_MAX;\n\t\t\tfor(int n:nums) m=min(m,n);\n\t\t\tint ans=0;\n\t\t\tfor(int n:num... |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 0 | {
"code": "\tclass Solution{\n\tpublic://Remember--whenever someone trash talks your country, state, city, home, community, etc--their feet are usually telling you that they're a liar.\n\t\tint minMoves(vector<int>& nums){\n\t\t\tint m=INT_MAX;\n\t\t\tfor(int n:nums) m=min(m,n);\n\t\t\tint ans=0;\n\t\t\tfor(int n:num... |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 2 | {
"code": "class Solution\n{\npublic:\n int minMoves(vector<int> &nums)\n {\n int sum = accumulate(nums.begin(), nums.end(), 0);\n int minElement = *min_element(nums.begin(), nums.end());\n return sum - minElement * nums.size();\n }\n};",
"memory": "31100"
} |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 2 | {
"code": "class Solution {\npublic:\n int minMoves(vector<int>& nums) {\n int sum = 0;\n int mini = INT_MAX;\n for(auto i:nums){\n sum += i;\n mini = min(mini,i);\n }\n return sum - (mini * nums.size());\n }\n};",
"memory": "31100"
} |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 2 | {
"code": "class Solution {\npublic:\n int minMoves(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL), cout.tie(NULL);\n\n int mini = *min_element(nums.begin(), nums.end());\n int ans = 0;\n for(int num: nums){\n ans += (num-mini);\n }\n\n... |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 2 | {
"code": "class Solution {\npublic:\n int minMoves(vector<int>& nums) {\n int ans = 0;\n int prev = 0;\n stable_sort(nums.begin(),nums.end());\n for(int i=1;i<nums.size();i++){\n int temp = ans;\n ans += prev + nums[i]-nums[i-1];\n prev = ans - temp;\n ... |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 2 | {
"code": "class Solution {\npublic:\n int minMoves(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n if(nums.size()==1) return 0;\n if(nums.size()==2) return abs(nums[1]-nums[0]);\n int n = nums.size();\n int ans = nums[n-1] - nums[n-2];\n int k = 1;\n for(in... |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 2 | {
"code": "class Solution {\npublic:\n int minMoves(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int maxi=nums[nums.size()-1];\n if(nums[0]==maxi){\n return 0;\n }\n int cnt=0;\n for(int i=1;i<nums.size();i++){\n cout<<nums[i]<<endl;\n ... |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 3 | {
"code": "class Solution {\npublic:\n int minMoves(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int maxi=nums[nums.size()-1];\n if(nums[0]==maxi){\n return 0;\n }\n int cnt=0;\n for(int i=1;i<nums.size();i++){\n cout<<nums[i]<<endl;\n ... |
453 | <p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the minimum number of moves required to make all array elements equal</em>.</p>
<p>In one move, you can increment <code>n - 1</code> elements of the array by <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong><... | 3 | {
"code": "class Solution {\npublic:\n int minMoves(vector<int>& nums) {\n std::sort(nums.begin(), nums.end());\n int ans = 0;\n for(std::size_t i = nums.size() - 1 ; i > 0 ; --i) {\n ans += nums[i] - nums[0];\n }\n return ans;\n }\n};",
"memory": "32100"
} |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n unordered_map<int, int> mp;\n int ans = 0, canVec = 0, offset = 2e5, m1 = INT_MAX, m2 = INT_MAX, n1 = INT_MIN, n2 = INT_MIN;\n for(int a: nums1) {m1 = min... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n unordered_map<int, int> mp;\n int ans = 0, canVec = 0, offset = 2e5, m1 = INT_MAX, m2 = INT_MAX, n1 = INT_MIN, n2 = INT_MIN;\n for(int a: nums1) {m1 = min... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n unordered_map<int, int> mp;\n int ans = 0, canVec = 0, offset = 2e5, m1 = INT_MAX, m2 = INT_MAX, n1 = INT_MIN, n2 = INT_MIN;\n for(int a: nums1) {m1 = min... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n unordered_map<int, int> mp;\n int ans = 0, canVec = 0, offset = 2e5, m1 = INT_MAX, m2 = INT_MAX, n1 = INT_MIN, n2 = INT_MIN;\n for(int a: nums1) {m1 = min... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n unordered_map<int, int> mp;\n int ans = 0, canVec = 0, offset = 2e5, m1 = INT_MAX, m2 = INT_MAX, n1 = INT_MIN, n2 = INT_MIN;\n for(int a: nums1) {m1 = min... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n unordered_map<int, int> mp;\n int ans = 0, canVec = 0, offset = 2e5, m1 = INT_MAX, m2 = INT_MAX, n1 = INT_MIN, n2 = INT_MIN;\n for(int a: nums1) {m1 = min... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)\n\nint minE(const vector<int> &v){\n return *min_element(v.begin(),v.end());\n}\nint maxE(const vector<int> &v){\n return *max_element(v.begin(),v.end());\n}\n\n int fourSumCount(vector<int>& nums1, vector<int>&... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n unordered_map<int, int> mp;\n int ans = 0, canVec = 0, offset = 2e5, m1 = INT_MAX, m2 = INT_MAX, n1 = INT_MIN, n2 = INT_MIN;\n for(int a: nums1) {m1 = min... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n void sort(vector<int> &nums){\n std::sort(nums.begin(), nums.end());\n }\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n int n = nums1.size();\n sort(nums1);\n sort(nums2);\n sort(... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n \n // Sort all input arrays\n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n sort(nums3.begin(), nums3.end());\n ... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n unordered_map<int, int> mp;\n vector<int> v;\n int ans = 0, canVec = 0, offset = 1e5, m = 0;\n for(int a: nums1) m = max(abs(a), m);\n for(i... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n unordered_map<int, int> mp;\n vector<int> v;\n int ans = 0, canVec = 0, offset = 1e5, m = 0;\n for(int a: nums1) m = max(abs(a), m);\n for(i... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n unordered_map<int, int> mp;\n vector<int> v;\n int ans = 0, canVec = 0, offset = 2e5, m = 0;\n for(int a: nums1) m = max(abs(a), m);\n for(i... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n int N = nums1.size(), count = 0;\n // create a map to count the freq of 2sum\n unordered_map<int, int> twoSum;\n for(int i=0; i<N; ++i) {\n ... |
454 | <p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>
<ul>
<li><code>0 <= i, j, k, l < n</code></li>
<li><code>nums1[i] + nums2[j] + nums3[k] + nums4[l] =... | 0 | {
"code": "class Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n std::unordered_map<int, int> map12;\n for (int x1 : nums1) {\n for (int x2 : nums2) {\n map12[x1+x2]++;\n }\n }\n\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.