id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 1 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& indices) {\n // index, length of [0:index)\n int n = nums.size(), m = indices.size();\n int l = 1, r = m;\n while(l <= r){\n int mid = (l+r)/2;\n if(success(nums,... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool solve(int mid,vector<int>&nums,vector<int> changeIndices){\n long long n=nums.size(),m=changeIndices.size();\n vector<long long > lastIndices(n+1,-1);\n for(int i=mid-1;i>=0;i--){\n if(lastIndices[changeIndices[i]]==-1)\n l... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\n bool check(int m, vector<int>& changeIndices, vector<int>& nums){\n stack<int> s;\n set<int> st;\n for(int i = m-1; i >= 0; i--){\n if(st.find(changeIndices[i]) == st.end()){\n s.push(changeIndices[i]);\n st.insert(changeIn... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool binarySearch(vector<int>& nums, vector<int>& changeIndices, int idx) {\n unordered_map<int, int> last;\n for (int i = 0; i < idx; i++) {\n last[changeIndices[i]] = i;\n }\n if (last.size() != nums.size()) return false;\n int ... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution\n{\n int m, n;\n bool isValid(int seconds, vector<int> changeIndices, vector<int> nums) {\n\n vector<int> lastPosition(n+1, -1);\n\n for (int i = 0; i <= seconds; i++) {\n int idx = changeIndices[i];\n lastPosition[idx] = i+1;\n }\n\n f... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "//T.C : O(log(m) * (m + nlogn)\n//S.C : O(n)\nclass Solution {\n\n int m, n;\n bool isValid(int seconds, vector<int> changeIndices, vector<int> nums) {\n\n vector<int> lastPosition(n+1, -1);\n\n for (int i = 0; i <= seconds; i++) {\n int idx = changeIndices[i];\n l... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool checker(vector<int>& nums, vector<int>& changeIndices, int m) {\n map<int, int> lastOccurence;\n for(int i = m; i >= 0; i--) {\n if(lastOccurence.count(changeIndices[i])) {\n continue;\n } else {\n lastOcc... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool helper(vector<int> &nums,vector<int> &second,int m){\n int n=nums.size();\n vector<int> last(n+1,-1);\n for(int i=0;i<m;i++){\n last[second[i]]=i;\n }\n priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> pq;... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\nprivate:\n bool isPossible(int mid,vector<int> &nums,vector<int> &indices){\n map<int,int> mp;\n for(int i=0;i<=mid;i++){\n mp[indices[i]] = i+1;\n }\n\n set<pair<int,int>> s;\n for(auto it:mp){\n s.insert({it.second,it.first});\n ... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& a, vector<int>& ci) {\n int n = a.size(); int m = ci.size();\n //convert change index to 0-indexing\n for(auto& c : ci) c-=1;\n\n //possible result r is in [1, m]\n for(int r = 1; r<=m; r++){\n ... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& a, vector<int>& ci) {\n int n = a.size(); int m = ci.size();\n for(auto& c : ci) c-=1;\n\n for(int r = 1; r<=m; r++){\n vector<int> last(n, -1);\n int marked = 0;\n int cnt = 0;... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution\n{\n bool areAllIndicesMarked(int time, vector<int> &nums, vector<int> &changeIndices)\n {\n int n = nums.size();\n int m = changeIndices.size();\n\n vector<int> lastPosition(n + 1, -1);\n\n for (int i = 0; i <= time; i++)\n {\n int idx = c... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "#define pii pair<int, int>\n#define F first\n#define S second\n\nclass Solution {\n \n int n;\n vector<int> arr;\n vector<int> ci;\n \n bool IsValid (int till) {\n vector<int> pos(n+1, -1);\n for (int j = 0; j <= till; j ++) pos[ci[j]] = j;\n \n for (int j = 1;... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\n int n;\n vector<int> arr;\n vector<int> ci;\n\n bool isvalid(int till){\n vector<int> pos(n+1, -1);\n for(int j=0; j<=till; j++){\n pos[ci[j]] = j;\n }\n\n for(int j=1; j<=n; j++){\n if(pos[j] == -1) return false;\n }\n... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n int n=nums.size();\n int m=changeIndices.size();\n for(int time=n;time<=m;time++){\n if(allIndicesMarked(time,nums,changeIndices)){\n return time;... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n\n int m, n;\n\n bool allidxmarked(int seconds, vector<int>& changeIndices, vector<int>& nums) {\n vector<int> lastocc(n + 1, -1);\n\n for (int i = 0; i <= seconds; i++) {\n int idx = changeIndices[i];\n lastocc[idx] = i + 1; // timing is... |
3,292 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canbemarked(int second, vector<int>& nums, vector<int>& changeIndices){\n int n=nums.size();\n int m=changeIndices.size();\n\n vector<int> maxWait(n+1,-1);\n for(int i=0; i<second; i++){\n maxWait[changeIndices[i]] = i+1;\n }... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "// Time: O((m + nlogn) * logm)\n// Space: O(n)\n\n// binary search, greedy, heap\nclass Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n vector<int> lookup(size(nums), -1);\n for (int i = size(changeIndices) - 1; i >= 0; --i) {\n ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "using ll = long long;\n\nclass Solution {\npublic:\n\n static constexpr int nm = 5002;\n\n int n, m;\n bool seen[nm];\n bool isFirst[nm];\n ll sum;\n\n bool ok(int m, vector<int> &nums, vector<int> &idx) {\n priority_queue<int> pq;\n ll sumPq = 0;\n for (int i = m - 1... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n int l = 0;\n for(auto& num:nums){\n if(num==0) l++;\n else l+=2;\n }\n int r = changeIndices.size();\n int res = -1;\n while(l<=r... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "class Solution {\npublic:\n long tot;\n int n, m;\n vector <int> sets;\n bool check(vector<int>& a, vector<int>& b, int k) {\n int n = a.size();\n priority_queue <int, vector <int>, greater <int>> q; // \n long sets_tot = 0;\n for (int j = k - 1; j >= 0; j--) {\n ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& a, vector<int>& c) {\n int n = a.size(),m = c.size();\n int lo = n,hi = m,ans = -1;\n long long tot = accumulate(a.begin(),a.end(),0ll) + n;\n while(hi >= lo)\n {\n int x = (hi + lo)/2;... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n for(auto& ind : changeIndices) ind--;\n int l = 1, r = changeIndices.size(), ans = -1; \n while(l <= r) {\n int mid = l + (r - l) / 2;\n if(ok(... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "class Solution {\npublic:\n map<int,int> mfirst;\n long long suma;\n vector<int> a,b;\n bool Check(int ri)\n {\n int cnt=0;\n priority_queue<int,vector<int>,greater<int>> pq;\n for(int t=ri;t>=0;--t)\n {\n int i=b[t]-1;\n if(a[i]<=1 || mfirst... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n int n = (int)size(nums), m = (int)size(changeIndices);\n // Observation 1: it's always better to change nums[i] to zero directly than \n // decrement, if possible (i.e. if ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "class Solution {\npublic:\n \n bool valid(unordered_map<int, int>& map, vector<int>& nums, vector<int>& changeIndices, int time) {\n long long free = 0;\n \n long long total = 0;\n for (auto num: nums) {\n total += num + 1;\n }\n \n priority... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "class Solution {\n public:\n int earliestSecondToMarkIndices(vector<int>& nums,\n vector<int>& changeIndices) {\n const long numsSum = accumulate(nums.begin(), nums.end(), 0L);\n // {the second: the index of nums can be zeroed at the current second}\n const unorde... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n const long nums_sum = std::accumulate(nums.begin(), nums.end(), 0L);\n const int n = static_cast<int>(changeIndices.size());\n std::unordered_map<int, int> first_to_index, ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n const long nums_sum = std::accumulate(nums.begin(), nums.end(), 0L);\n const int n = static_cast<int>(changeIndices.size());\n std::unordered_map<int, int> first_to_index, ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "// Idea: binary search for optimization? it seems easier to verify if a given\n// time duration is enough than to directly compute for the optimal time. the\n// problem has the monotonic structure required for binary search: if duration t\n// works, then t+1 works as well.\n//\n// Greedy, with a PQ to decr... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 0 | {
"code": "#define ll long long\nclass Solution {\npublic:\n \n bool Check(const vector<int>& nums, const vector<int>& CI, int maxx) {\n // 1 to maxx\n int n=nums.size();\n vector<int> earliest_set(n+1,-1);\n for(int i=1;i<=maxx;i++) {\n int c = CI[i-1];\n if (e... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 1 | {
"code": "// Idea: binary search for optimization? it seems easier to verify if a given time duration is\n// enough than to directly compute for the optimal time. the problem has the monotonic structure\n// required for binary search: if duration t works, then t+1 works as well.\n//\n// Greedy, with a PQ to decremen... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 1 | {
"code": "// Idea: binary search for optimization? it seems easier to verify if a given time duration is\n// enough than to directly compute for the optimal time. the problem has the monotonic structure\n// required for binary search: if duration t works, then t+1 works as well.\n//\n// Greedy, with a PQ to decremen... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 1 | {
"code": "#define ll long long\nclass Solution {\npublic:\n \n bool Check(const vector<int>& nums, const vector<int>& CI, int maxx) {\n // 1 to maxx\n int n=nums.size();\n vector<int> earliest_set(n+1,-1);\n for(int i=1;i<=maxx;i++) {\n int c = CI[i-1];\n if (e... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 1 | {
"code": "#define ll long long\nclass Solution {\npublic:\n \n bool Check(const vector<int>& nums, const vector<int>& CI, int maxx) {\n // 1 to maxx\n int n=nums.size();\n vector<int> earliest_set(n+1,-1);\n for(int i=1;i<=maxx;i++) {\n int c = CI[i-1];\n if (e... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n \n bool Check(const vector<int>& nums, const vector<int>& CI, int maxx) {\n // 1 to maxx\n int n=nums.size();\n vector<int> earliest_set(n+1,-1);\n for(int i=1;i<=maxx;i++) {\n int c = CI[i-1];\n if (e... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n bool check(vector<int>& nums, vector<int>& idx, int s) {\n int n = nums.size();\n\n long long sum = 0; // total op needed\n for (int x : nums)\n sum += x + 1; \n\n vector<int> firstOccur(n, -1);\n ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "#define ll long long\nclass Solution {\n bool isp(vector<int>& a, vector<int>& ci,int s)\n {\n ll n=a.size(),m=ci.size();\n vector<int>first(n,-1);\n priority_queue<ll,vector<ll>,greater<ll>>pq;\n for(int i=0;i<=s;i++)\n {\n if(first[ci[i]]==-1)\n ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n\n bool isPossible(vector<int> nums, vector<int>& changeIndices, int right){\n int n = nums.size();\n vector<int>firstIndex(n, -1);\n for(int i=0; i<right; i++){\n if (firstIndex[changeIndices[i]-1] == -1){\n ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool f(long long k, vector<int> v, vector<int>& C){\n long long n = v.size();\n long long s = 0;\n for(int i : v) s += i;\n if(k == 1){\n if(v[0] == 0) return true;\n return false;\n }\n priority_queue<pair<int,i... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool func (vector<int>& nums, vector<int>& c, int limit)\n {\n vector<int> first_occ(nums.size(), -1);\n vector<int> marked(nums.size(), 0);\n int can_mark = 0, sz = limit+1;\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<in... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool func (vector<int>& nums, vector<int>& c, int limit)\n {\n vector<int> first_occ(nums.size(), -1);\n vector<int> marked(nums.size(), 0);\n int can_mark = 0, sz = limit+1;\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<in... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n\n bool isItPossible(vector<int> & nums, vector<int> & v, int m) {\n \n long long int tot = 0;\n\n vector<int> temp(nums.size() + 1, -1);\n vector<int> taken(v.size() + 1);\n priority_queue<int, vector<int>, greater<int>> pq;\n\n for(i... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n\n bool isItPossible(vector<int> & nums, vector<int> & v, int m) {\n \n long long int tot = 0;\n\n vector<int> temp(nums.size() + 1, -1);\n vector<int> taken(v.size() + 1);\n priority_queue<int, vector<int>, greater<int>> pq;\n\n for(i... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n\n bool check(vector<int>& a, vector<int>& c, vector<int>& early, int t) {\n int n = a.size(), m = c.size();\n int wait = 0;\n vector<pair<int, int>> q;\n for (int i = 0; i < n; ++i) {\n if (a[i] == 0) wait++;\n else if (early[... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& ci) {\n long long ans=-1;\n long long n=nums.size(),m=ci.size();\n long long l=0,h=m;\n //cout<<n<<\" \"<<m<<endl;\n long long sum=0;\n for(long long i=0;i<n;i++)sum+=(lo... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums,\n vector<int>& changeIndices) {\n for (int i = 0; i < changeIndices.size(); i++) {\n changeIndices[i] -= 1;\n }\n long long int time = 0;\n int rem = n... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums,\n vector<int>& changeIndices) {\n for (int i = 0; i < changeIndices.size(); i++) {\n changeIndices[i] -= 1;\n }\n long long int time = 0;\n int rem = n... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums,\n vector<int>& changeIndices) {\n for (int i = 0; i < changeIndices.size(); i++) {\n changeIndices[i] -= 1;\n }\n long long int time = 0;\n int rem = n... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n int n = nums.size(),m = changeIndices.size();\n int l = n-1,r = m-1;\n long long sum = 0;\n for(auto i : nums)\n sum+=i;\n int res = -1;\n w... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\npublic:\ntypedef long long ll;\n bool canMark(int maxTime , vector<int>&nums,unordered_map<int,int>&mpp){\n ll timeAvl = 0 ;\n multiset<ll>st;\n for(int i=maxTime-1;i>=0;i--){\n if(mpp.find(i)!=mpp.end()){\n st.insert(nums[mpp[i]]);\n ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "#define pii pair<int, int>\n#define F first\n#define S second\n\nclass Solution {\n \n int n;\n vector<int> arr;\n vector<int> ci;\n \n bool IsValid (int till) {\n vector<int> first_occur (n+1, -1);\n for (int j = 0; j <= till; j ++) {\n if (first_occur[ci[j]] != ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "class Solution {\nprivate:\n bool ok(const vector<int>& A, const vector<int>& C, int ans) {\n int n = A.size(), m = C.size();\n if (ans == m + 1) {\n return true;\n }\n vector<bool> seen(n);\n vector<pair<int, int>> ps;\n for (int j = 0; j < ans; ++j)... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 2 | {
"code": "#define ll long long\n\nclass Solution {\n bool ok(const vector<int>& A, const vector<int>& C, int ans) {\n int n = A.size(), m = C.size();\n if (ans == m + 1) {\n return true;\n }\n \n vector<bool> seen(n);\n vector<pair<int, int>> ps;\n for (... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\nbool solve(const vector<int> &A,const vector<int>&C,int ans)\n{\n int n=A.size(),m=C.size();\n if(ans==m+1)\n {\n return true;\n\n }\n\n vector<bool> seen(n);\n vector<pair<int,int>> ps;\n for(int j=0;j<ans;j++)\n {\n if(!seen[C[j]-1])\n ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int t, long long sumNum, unordered_set<int> firstChangeIndices, \n vector<int>& nums, vector<int>& changeIndices) {\n // check if all nums can be marked within time 0 - t\n priority_queue<int, vector<int>, greater<int>> pq; // min-h... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "// 關鍵: 類似ladder crossing further building題, 先greedy拿,之後再還回來\n// 關鍵: priority_queue上的是可以直接zerolized的, 只是我們記住他的大小關係, 當有出現那種zerolized index但後面沒辦法被mark時, pq裡面最小的拿出來用減的\n // 考慮(nums = [..., 100, 5]), (changeIndices = [..., 100, 5] && 100跟5都只出現這一次)\n // pq = 5(top), 100\n // 我們就把100用zerolized, final day... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "// 關鍵: 類似ladder crossing further building題, 先greedy拿,之後再還回來\n// 關鍵: priority_queue上的是可以直接zerolized的, 只是我們記住他的大小關係, 當有出現那種zerolized index但後面沒辦法被mark時, pq裡面最小的拿出來用減的\n // 考慮(nums = [..., 100, 5]), (changeIndices = [..., 100, 5] && 100跟5都只出現這一次)\n // pq = 5(top), 100\n // 我們就把100用zerolized, final day... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool check(vector<int>& nums, vector<int>& changeIndices, int mid)\n {\n int n = nums.size(), m = changeIndices.size();\n long long tot = 0;\n for(auto it:nums)\n tot += it;\n priority_queue<int,vector<int>,greater<int> > pq;\n ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool check(vector<int>& nums, vector<int>& changeIndices, int mid)\n {\n int n = nums.size();\n int m = changeIndices.size();\n\n long long tot = 0;\n for(auto it:nums)\n {\n tot += it;\n }\n \n priority_que... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n // binary search ---> greedy ---> priority queue\n // time complexity= m(log(m)) where m= size of changeIndices vector\n\n bool markPossible(int sec, vector<int>& nums, vector<int>& changeIndices){\n\n long long requiredTime = 0;\n for(auto n: nums){\n ... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n using ll = long long;\n ll tot = accumulate(nums.begin(), nums.end(), 0ll);\n int n = nums.size();\n int m = changeIndices.size();\n ll lo = -1, hi = m;\n for (int... |
3,289 | <p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>
<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>... | 3 | {
"code": "class Solution {\npublic:\nbool fun( int maxt , vector<int>&a , vector<int>&ci){\n \n map < int , int > minind ; \n int n = a.size() ; \n vector<int>mark(n+1,-1) ; \n for(int i = 1 ; i <= maxt ; i++){\n int val = ci[i-1] ; \n if(mark[val] == -1)minind[i] = val , mark[val]... |
3,331 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you can remove one occurrence of the smallest element of <code>nums</code>.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed so that all elements of the arra... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n int ans = 0;\n for(int i =0;i<nums.size();i++){\n if(nums[i]>=k){\n ans++;\n }\n }\n return nums.size() - ans;\n }\n};",
"memory": "24000"
} |
3,331 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you can remove one occurrence of the smallest element of <code>nums</code>.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed so that all elements of the arra... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n int ans = 0;\n for (auto& num: nums) {\n if (num < k) ans++;\n }\n return ans;\n }\n};",
"memory": "24100"
} |
3,331 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you can remove one occurrence of the smallest element of <code>nums</code>.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed so that all elements of the arra... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n int count=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]<k){\n count++;\n }\n }\n return count;\n }\n};",
"memory": "24200"
} |
3,331 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you can remove one occurrence of the smallest element of <code>nums</code>.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed so that all elements of the arra... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n int count=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]<k) count++;\n }\n return count;\n }\n};",
"memory": "24200"
} |
3,331 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you can remove one occurrence of the smallest element of <code>nums</code>.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed so that all elements of the arra... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n int count = 0;\n sort(nums.begin(), nums.end());\n for (int i = 0; i < nums.size(); i++)\n {\n if (nums[i] < k)\n count++;\n }\n return count;\n }\n};",
"m... |
3,331 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you can remove one occurrence of the smallest element of <code>nums</code>.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed so that all elements of the arra... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n int count=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]<k)\n count++;\n }\n return count;\n }\n};",
"memory": "24300"
} |
3,331 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you can remove one occurrence of the smallest element of <code>nums</code>.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed so that all elements of the arra... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n int n = nums.size();\n int loops = 0;\n for(int i = 0; i < n; i++) {\n if (nums[i] < k) {\n loops++;\n } \n }\n \n return loops;\n }\n};\n\n/*\nCh... |
3,331 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you can remove one occurrence of the smallest element of <code>nums</code>.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed so that all elements of the arra... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n int cnt=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]<k) cnt++;\n }\n return cnt;\n }\n};",
"memory": "24400"
} |
3,331 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you can remove one occurrence of the smallest element of <code>nums</code>.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed so that all elements of the arra... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n int count=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]<k){\n count++;\n }\n }\n return count;\n }\n};",
"memory": "24500"
} |
3,331 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you can remove one occurrence of the smallest element of <code>nums</code>.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed so that all elements of the arra... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n long sum=0,count=0;\n for(auto x:nums){\n sum+=x;\n }\n for(int i=0;i<nums.size();i++){\n if(nums[i]<k){\n count++;\n ... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n make_heap(nums.begin(),nums.end(),[&](const int A, const int B){\n return A>B;\n });\n int result=0,min2;\n long long min1;\n while(nums[0]<k){\n min1=nums[0];\n ... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n ios::sync_with_stdio(0); cin.tie(0);\n if(nums.size() < 2) return 0;\n int result = 0, operation_result, first;\n\n std::priority_queue<int, std::vector<int>, std::greater<int>> min_nums(nums.begin(),... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n ios::sync_with_stdio(0); cin.tie(0);\n if(nums.size() < 2) return 0;\n int result = 0, operation_result, first, second;\n\n std::priority_queue<int, std::vector<int>, std::greater<int>> min_nums(nums.... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n if(nums.size() < 2) return 0;\n int result = 0, operation_result, first, second;\n\n std::priority_queue<int, std::vector<int>, std::greater<int>> min_nums(nums.begin(), nums.end());\n\n auto operatio... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n \n priority_queue<long long, vector<long long>, greater<long long>> pq{nums.begin(), nums.end()};\n int op = 0;\n\n while(pq.top() < k)... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long, vector<long>, greater<>> min_pq(nums.begin(), nums.end());\n int ans = 0;\n while (min_pq.size() >= 2 && min_pq.top() < k) {\n ++ans;\n long a = min_pq.top();\n ... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long, vector<long>, greater<long>>pq(nums.begin(),nums.end());\n int c=0;\n while(pq.size() > 1){\n long a = pq.top();\n pq.pop();\n long b = pq.top();\n ... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long long,vector<long long>,greater<long long>>pq(nums.begin(),nums.end());\n\n int operation=0;\n while(pq.top()<k && pq.size()>1){\n operation++;\n long long x=pq.top()... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long, vector<long>, greater<long>>pq(nums.begin(),nums.end());\n int c=0;\n while(pq.size() > 1){\n long a = pq.top();\n pq.pop();\n long b = pq.top();\n ... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<int, vector<int>, greater<int>> pq;\n for(auto it:nums){\n if(it<k) pq.push(it);\n }\n int ans=0;\n while(pq.size()>1){\n int a = pq.top();\n pq.... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue <int, vector<int>, greater<int>> queue;\n int skipedNums = 0;\n for (int num : nums) {\n if (num < k)\n queue.push(num);\n else \n skipedNum... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<int,vector<int>,greater<int>>pq;\n for(auto it:nums){\n if(it<k){\n pq.push(it);\n }\n }\n int cnt = 0;\n while(!pq.empty()){\n auto ele = p... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "\nclass Solution {\npublic:\n int minOperations(vector<int>& a, int k) {\n int n = a.size(), ct = 0, x, y;\n priority_queue<int, vector<int>, greater<int>> pq;\n\n for (int i = 0; i < n; i++) \n pq.push(a[i]);\n \n while(pq.top() < k){\n x = pq.to... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<int, vector<int>, greater<int>> pq;\n int ans=0, cal;\n for(int i=0; i<nums.size(); i++) pq.push(nums[i]);\n while(pq.size()>1){\n long long temp=pq.top();\n pq.po... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n int res = 0;\n sort(nums.begin(), nums.end());\n\n //use 2 array, 2 pointer method\n vector<long long> sec; //initial a vector\n //generate first item in sec\n int p1 = 0;\n int p... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "#define ll long long\nclass Solution {\npublic:\n int minOperations(vector<int>& a, int k) \n {\n priority_queue<ll,vector<ll>,greater<ll>>pq;\n for(auto &x:a)\n {\n pq.push(x);\n }\n int count=0;\n while(!pq.empty())\n {\n ll x=pq.... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "auto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 'c';\n}();\nclass Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n if(nums.size()<2) return -1;\n int c=0;\n priority_queue <long long int, vector<long long i... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) \n {\n cin.tie(0);\n cout.tie(0);\n ios_base::sync_with_stdio(false);\n priority_queue<long long int, vector<long long int>, greater<long long int>> pq; \n for (long long int it : nums) {\n ... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n ios::sync_with_stdio(0); cin.tie(0);\n if(nums.size()<2) return 0;\n priority_queue<long long,vector<long long>,greater<long long>>pq;\n for(long long i=0;i<nums.size();i++){\n pq.push(nums... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long long,vector<long long>,greater<long long>>pq;\n for(auto i : nums){\n if(i>=k)continue;\n pq.push(i);\n }\n sort(nums.begin(),nums.end());\n \n ... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long, vector<long>, greater<long>> minPQ1;\n for(int& x : nums)\n if(x < k) minPQ1.push(x);\n int ops = 0;\n while(!minPQ1.empty())\n {\n auto top1 = minPQ1... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long long,vector<long long>,greater<long long>>pq;\n int c=0;\n for(auto i:nums)\n {\n if(i<k)\n {\n pq.push(i);\n }\n }\n ... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long long ,vector<long long >,greater<long long >>pq;\n for(auto it:nums)\n {\n pq.push(it);\n }\n \n int cnt=0;\n while(!pq.empty() && pq.top()<k)\n ... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long long int, vector<long long int>, greater<long long int>> pq; \n\n for (long long int it : nums) {\n pq.push(it);\n }\n\n long long int ans = 0;\n while (pq.top()... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long long,vector<long long>,greater<long long> > q{};\n for(auto num : nums) q.push(num);\n int iters = 0;\n while(q.size()>=2 && q.top()<k){\n iters++;\n auto a =... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long long, vector<long long>, greater<long long>> minHeap;\n for(auto &i: nums)\n minHeap.push(i);\n\n int ans = 0;\n while(minHeap.size()>=2){\n long long small =... |
3,332 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p>
<p>In one operation, you will:</p>
<ul>
<li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li>
<li>Remove <code>x</code> and <code>y</code> from <code>nums</code... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<long long,vector<long long>,greater<long long>> minh;\n long long lessthank = 0;\n for(auto it:nums){\n if(it<k) lessthank++;\n minh.push(it);\n }\n int ans... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.