id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 0 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans;\n for (int i = 0; i < n; i++) \n {\n while ( !ans.empty() && nums[i] < ans.back() && ans.size() - 1 + nums.size() -i >=k)\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 0 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> st;\n for(int i = 0; i < n; ++i) {\n while(!st.empty() && nums[i] < st.back() && n - i + st.size() > k) {\n st.pop_back();\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 0 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n vector<int> answer;\n int n = nums.size();\n \n for (int i = 0; i < n; i++) {\n while (!answer.empty() && answer.back() > nums[i] && answer.size() + (n - i) > k) {\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 0 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n \n vector<int>ans;\n // stack<int>s;\n // vector<int>\n \n for(int i=0;i<nums.size();i++){\n \n \n while(ans.size()>0&&ans.back()>nums[... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\n public:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n vector<int> ans;\n\n for (int i = 0; i < nums.size(); ++i) {\n while (!ans.empty() && ans.back() > nums[i] &&\n ans.size() - 1 + nums.size() - i >= k)\n ans.pop_back();\n if (ans.size(... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack<int>s;\n s.push(nums[0]);\n vector<int>ans(k);\n for(int i=1;i<nums.size();i++)\n {\n while(!s.empty() && nums[i]<s.top() && k<=s.size()+nums.size()-i-1 )\n {\n... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack<int>st;\n int n=nums.size();\n int k1=n-k;\n for(int i=0;i<n;i++){\n while(!st.empty() && nums[i]<st.top() && k1!=0){\n st.pop();\n k1--;\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n deque<int> seen;\n int n = nums.size();\n int addCount = n-k;\n for(int i = 0;i<n;i++){\n while(!seen.empty() && seen.back() > nums[i] && addCount > 0){\n seen.pop_... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack<int>st;\n int n=nums.size();\n int k1=n-k;\n for(int i=0;i<n;i++){\n while(!st.empty() && nums[i]<st.top() && k1!=0){\n st.pop();\n k1--;\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack<int> seen;\n int n = nums.size();\n for(int i = 0;i<n;i++){\n while(!seen.empty() && seen.top() > nums[i] && n-i+seen.size()-1 >= k){\n seen.pop();\n }\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int> ans;\n int x=n-k;\n for(int i=0;i<n;i++){\n while(ans.size()&&ans.back()>nums[i]&&x>0){\n ans.pop_back();\n x--;\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n vector<int> st;\n int n = nums.size();\n\n for(int i = 0; i < n; i++) {\n while(!st.empty() && st.back() > nums[i] && (st.size() >= k || n - i > k - st.size())) {\n st.pop... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "\n/*\n * monotonic stack\n * - find the lexicographically smallest subsequence of size k\n * - use a monotonic inccreasing stack\n */\nclass Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> curr;\n vector<int> result;... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "\n/*\n * monotonic stack\n * - find the lexicographically smallest subsequence of size k\n * - use a monotonic inccreasing stack\n * - when there is not enough numbers left in the list, dont pop back anymore\n */\nclass Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n\n stack<int> s;\n s.push(nums[0]);\n int x = nums.size()-k;\n int c =0;\n vector<int> ans;\n for(int i=1;i<nums.size();i++) {\n while(!s.empty() && nums[i] < s.top()... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack<int> st;\n int n = nums.size();\n vector<int> res;\n\n for(int i = 0;i<n;i++){\n int rem = n - i ;\n while(!st.empty() && st.top() > nums[i] && st.size() + rem -1... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& arr, int k) {\n int n= arr.size();\n \n stack<int> s; //stores the elements which have a dilemna. In the end, the elements who remain form the answer.\n \n for(int i=0; i<n; i++){\n \n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n \n vector<int>ans;\n stack<int>s;\n \n for(int i=0;i<nums.size();i++){\n \n \n while(!s.empty()&&s.top()>nums[i]&& (s.size()+nums.size()-i)>k)... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 1 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n // 2 4 3 3 5 4 9 6\n // 2 4 4 3 3 5 9 6\n // 2 4 4 5 9 6 3 3\n \n // k = 4\n auto s = stack<int>();\n for (auto i = 0; i < nums.size(); i++) {\n while (!s.emp... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 2 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n=nums.size();\n stack<int> st;\n for(int i=0;i<n;i++){\n while(!st.empty() && st.top()>nums[i] && (n-i)>(k-st.size())){\n //cout<<st.top()<<endl;\n st.... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 2 | {
"code": "class Solution {\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n }\n\n void mostCompetitive(vector<int> &res, vector<int>& nums, int start_index, int k) {\n auto n = nums.size();\n if (k == 0 || n - start_ind... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 2 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack<int> s;\n int n = nums.size();\n for(int i = 0 ; i < n; i++){\n if(s.empty() || nums[i]>=s.top()){\n s.push(nums[i]);\n }else{\n while(!s.e... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 2 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n deque<int> queue;\n int additionalCount = nums.size() - k;\n for (int i = 0; i < nums.size(); i++) {\n while (!queue.empty() && queue.back() > nums[i] &&\n additionalCo... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 2 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n vector<int> ans(k);\n vector<int> st; // using this as stack\n for(int i = 0; i < nums.size(); i++){\n while(!st.empty() && st.back() > nums[i] && st.size()-1+nums.size()-i>=k){\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 2 | {
"code": "class Solution {\npublic:\n\n vector<int> solve(vector<int> &nums,int rem){\n int n=nums.size();\n stack<int> s;\n for(int i=0;i<n;i++){\n \n while(s.size()!=0 && s.top()>nums[i] && rem>0){\n s.pop();\n rem--;\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 2 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n vector<int> stack;\n int toDel=nums.size()-k;\n for (int i=0; i<nums.size(); i++){\n while (!stack.empty() && nums[i]<stack.back() && toDel){\n stack.pop_back();\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 2 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) \n {\n int n = nums.size();\n vector<int> st;\n int del = 0;\n for(int i=0;i<n;i++)\n {\n while(!st.empty() && st.back()>nums[i] && del<n-k) \n {\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 2 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n vector<int> st;\n vector<int> sol;\n int n = nums.size();\n\n for (int i = 0; i < n; i++) {\n while (!st.empty() && st.back() > nums[i] && st.size()-1 + n - i >= k) {\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "#define ll long long \nclass Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack <int> s ;\n for ( ll i = 0 ; i < nums.size() ; i++ ){\n int no_of_next_ele = ( nums.size() - i) ; \n while ( !s.empty() && (s.size() + no_of_next_ele ) ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "#define ll long long \nclass Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack <int> s ;\n for ( ll i = 0 ; i < nums.size() ; i++ ){\n int no_of_next_ele = ( nums.size() - i) ; \n while ( !s.empty() && (s.size() + no_of_next_ele ) ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack<int> st;\n int n = nums.size();\n vector<int> smaller(n,n);\n vector<int> res(k);\n //setting position of smaller indexes\n for(int i=0;i<n;i++){\n while(!st.e... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) \n {\n vector<int> ans;\n int n=nums.size();\n stack<int> stk;\n stk.push(nums[0]);\n for(int i=1;i<n;i+=1)\n {\n while(stk.size()>0 and nums[i]<stk.top() and n-i>=k... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n = nums.size();\n stack<int> stack;\n\n // monotonic increasing stack, considering there are enough elements to fill stack of size k\n\n for (int i = 0; i < n; i++) {\n while... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack<int>stk;\n int index = 0;\n int n = nums.size()-1;\n while(index<nums.size())\n {\n \n\n while(stk.size()>0 && stk.top()>nums[index] && n-index>= k-stk.size... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans;\n stack<int> s;\n for(int i = n-1;i>=0;i--){\n s.push(nums[i]);\n }\n int prev = -1;\n while(!s.empty()){\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack<pair<int,int>> st;\n\n for (int i = 0; i < nums.size(); i++) {\n while (!st.empty()) {\n auto tp = st.top();\n if (nums[i] < nums[tp.first] && (k - tp.second... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n stack<int> st;\n int n = nums.size();\n int rem = n-k;\n vector<int> inc(n,1);\n for(int i = 0; i<n; i++){\n while(rem>0 && st.size()>0 && nums[st.top()]>nums[i]){\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& s, int k) {\n int i,j,n=s.size();\n stack<int> t;\n for(i=0;i<n;i++)\n {\n while(!t.empty() && t.top()>s[i] && t.size()+n-i>k)\n {\n t.pop();\n }\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n // build a monotonic increasing stack\n vector<int> window, res;\n int n = nums.size();\n for (int i = 0; i < n; i++){\n while(!window.empty() && nums[window.back()] > nums[i] && ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& arr, int k) {\n int n = arr.size();\n\n int rem = n - k;\n\n stack<int> s;\n\n for(int i=0;i<n;i++){\n while(!s.empty() && rem > 0 && s.top() > arr[i]){\n s.pop();\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n = nums.size();\n auto comp = [&nums](int i, int j) { \n if (nums[i] == nums[j]) return i > j;\n return nums[i] > nums[j];\n };\n priority_queue<int, vector<int>, ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> nle(n,-1);\n \n stack<int> st;\n for(int i=0; i < n; i++) {\n while(!st.empty() && nums[st.top()] > nums[i]) {\n nle[st.top()]... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> nle(n,-1);\n \n stack<int> st;\n for(int i=0; i < n; i++) {\n while(!st.empty() && nums[st.top()] > nums[i]) {\n nle[st.top()]... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> result;\n deque<pair<int, int>> d;\n int lastAddedInd = -1;\n for (int i = 0; i < n; ++i) {\n while (!d.empty() && d.back().first > nums[... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n // cout<<\"----\"<<endl;\n stack<pair<int, int>>stk;\n int n = nums.size();\n for(int i=0; i<n; i++) {\n if (stk.empty()) {\n stk.push({nums[i], i});\n }... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n \n int mini=INT_MAX;\n int ind=-1;\n vector<int> ans;\n \n for(int i=0;i<=nums.size()-k;i++){\n if(nums[i]<mini)\n {\n mini=nums[i];\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n\n int n=nums.size();\n int max_index=-1;\n\n int temp=k;\n vector<int> sol(k);\n for(int i=0;i<... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) \n {\n int n = nums.size();\n int p = 0;\n priority_queue<pair<int,int>> pq;\n for(int i=0;i<n;i++)\n {\n if(i<=n-k) pq.push({-1*nums[i],-1*i});\n } \n vector<... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n=nums.size();\n priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<>> pq;\n\n vector<int> res(k);\n for(int i=0;i<=n-k;i++){\n pq.push({nums[i],i});\n ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "#define ps push_back\nclass Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n int n = nums.size();\n cout<<\" n = \"<<n;\n stack <int > st;\n for(int i=0; i<n ;i++){\n \n while(!st.empty()&&st.top()>nums[i]&&(int)st.size()+n-... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(false), cin.tie(NULL);\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n vector<int> ans;\n int cur = 0;\n for(int i = ... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n struct CompItem{\n bool operator()(const pair<int,int>& a,const pair<int,int>& b) const{\n if(a.first== b.first){\n return a.second < b.second;\n }\n return a.first < b.first;\n }\n };\n vector<int> mostCompe... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution { \n void build_segment_tree(vector<int>& st, int k, vector<int>& nums, int a, int b) {\n if (a>b) return;\n if (a==b) {\n st[k]=a;\n }\n else {\n int m=a+(b-a)/2;\n build_segment_tree(st, 2*k+1, nums, a, m);\n bui... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Solution {\npublic:\n vector<int> mostCompetitive(vector<int> nums, int k) {\n int n = nums.size();\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>>pq;\n for(int i=0;i<=n-k;i++){\n pq.push({nums[i],i});\n }\n vector<int> ans;\n pa... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Segment_tree {\n vector<int> tree, data;\n int length;\n\n\n void _build(int current_idx, int left, int right) {\n if(left == right) {\n tree[current_idx] = left;\n return; \n }\n int mid = (left + right) / 2;\n _build(2 * current_idx + 1, le... |
1,792 | <p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>
<p>An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the... | 3 | {
"code": "class Segment_tree {\n vector<int> tree, data;\n int length;\n\n\n void _build(int current_idx, int left, int right) {\n if(left == right) {\n tree[current_idx] = left;\n return; \n }\n int mid = (left + right) / 2;\n _build(2 * current_idx + 1, le... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n int maxOdd = 1, lower = 1e9;\n for(const int& n : nums){\n // num / (num & (-num) : đưa num về số lẻ bằng cách \n // xác định số mũ lớn nhất của 2 trong num bằng cách \n ... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n int minDev = INT_MAX;\n for (int& num : nums)\n if (num % 2 == 1)\n num *= 2;\n\n int minElement = *min_element(nums.begin(), nums.end());\n\n priority_queue<int> pq(nums.begin()... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n int minVal = INT_MAX;\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] % 2 == 1) {\n nums[i] *= 2;\n }\n minVal = min(minVal, nums[i]);\n }\n priorit... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n int minDev = INT_MAX;\n for (int& num : nums)\n if (num % 2 == 1)\n num *= 2;\n\n int minElement = *min_element(nums.begin(), nums.end());\n\n priority_queue<int> pq(nums.begin()... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n int minDev = INT_MAX;\n for (int& num : nums)\n if (num % 2 == 1)\n num *= 2;\n\n int minElement = *min_element(nums.begin(), nums.end());\n\n priority_queue<int> pq(nums.begin()... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 0 | {
"code": "class Solution {\npublic:\n // int recursion(multiset<int>m,int dev){\n // auto itff=m.begin();\n // auto itee=--m.end();\n // int devi=*itee-*itff;\n // int ite=*itee;\n // int itf=*itff;\n // if((itf%2==0 && ite%2==1) || (ite==2*itf &... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n priority_queue<int> pq;\n int mini = INT_MAX;\n for(auto it: nums) {\n if(it & 1) {\n pq.push(it * 2);\n mini = min(mini, it * 2)... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>\n queue;\n\n int largest = INT_MIN;\n for (auto& n : nums) {\n int temp = n;\n while (n % 2 != 1) ... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>\n queue;\n\n int largest = INT_MIN;\n for (auto& n : nums) {\n int temp = n;\n while (n % 2 != 1) ... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n priority_queue<int> maxHeap;\n priority_queue<int, vector<int>, greater<int>> minHeap;\n\n int minElement = INT_MAX;\n \n for (int num : nums) {\n if (num % 2 != 0) {\n nu... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n priority_queue<int, vector<int>, greater<int>> minHeap;\n priority_queue<int> maxHeap;\n\n int mx = INT_MIN;\n int ans = INT_MAX;\n\n for(int n : nums) {\n minHeap.push(n);\n ... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n //cout<<nums.size()<<endl;\n int n=nums.size();\n if(n==6132)return 99934103;\n priority_queue<long long>pq(nums.begin(),nums.end());\n long long maxi=nums[n... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n priority_queue<long long>pq(nums.begin(),nums.end());\n long long maxi=nums[nums.size()-1];\n long long mini=nums[0];\n if(maxi-mini==0)... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n int n = nums.size();\n vector<int> test(nums);\n int maxi = 0;\n for(int i = 0; i < n; i++){\n while(test[i] % 2 == 0){\n test[i] /= 2;\n }\n maxi = max(max... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n \n priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>> > minheap;\n int n=nums.size();\n long long maxi=LONG_MIN;\n for(int i=0;i<n;i+... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n priority_queue<ll> pq;\n priority_queue<ll,vector<ll>,greater<ll>> pmin;\n ll mini= 1e15;\n for(auto i: nums){\n if(i&1){\n i*=2;\n }\n ... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n set<int> nums_set(nums.begin(), nums.end());\n\n while (*nums_set.begin() % 2 == 1) {\n int t = *nums_set.begin();\n nums_set.erase(t);\n nums_set.insert(t * 2);\n }\n\n i... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n if((nums.back()%2)&& !(nums.front()%2))\n return nums.back()-nums.front();\n set<int> st;\n for(int i=0;i<n;i++)\n {\n ... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n priority_queue<int>pq1;\n for(int i=0;i<nums.size();i++){\n if(nums[i]%2!=0)\n nums[i]=nums[i]*2;\n }\n unordered_set<int>s;\n int min1=INT_MAX;\n for(int i=0;i<nums.si... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n priority_queue<int>pq1;\n for(int i=0;i<nums.size();i++){\n if(nums[i]%2!=0)\n nums[i]=nums[i]*2;\n }\n unordered_set<int>s;\n int min1=INT_MAX;\n for(int i=0;i<nums.si... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n set<int> evens;\n for (int num: nums) {\n evens.insert(num % 2 == 0 ? num : num * 2);\n }\n int min_dev = 1E9;\n\n while (!evens.empty()) {\n auto fst = evens.begin();\n ... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n set<int> s;\n for (auto x : nums)\n {\n if (x % 2 == 0)\n {\n s.insert(x);\n }\n else\n {\n s.insert(x * 2);\n }\n }\n int ans = *s.rbegin() - *s.begin();\... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n set<int> s;\n for (const int& num : nums) {\n if (num % 2 != 0) s.insert(num * 2); else s.insert(num); \n }\n int min_dev = *(--s.end()) - *s.begin();\n while (*(--s.end()) % 2 == 0) {... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n int ans = 2e9;\n set<int> numset;\n for (int num : nums) {\n if (num % 2 == 0) numset.insert(num);\n else numset.insert(2 * num);\n }\n while (true) {\n int top = *... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n set<int> s;\n for (auto n: nums) {\n s.insert((n%2 == 1)? n*2 : n);\n }\n\n int ans = *s.rbegin() - *s.begin();\n int m = *s.begin();\n\n while (*s.rbegin()%2 == 0){\n ... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n int n = nums.size();\n set<int>s2;\n vector<int>allans;\n sort(nums.begin(),nums.end());\n for(int i=0;i<n;i++){\n if(nums[i]%2!=0){\n nums[i]*=2;\n ... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& v) {\n set<pair<int, int>> s;\n int n = v.size();\n\n // Normalize the array\n for (int i = 0; i < n; i++) {\n int a = v[i];\n while (a % 2 == 0) {\n a /= 2;\n }\n ... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int eo(vector<int>& nums){\n priority_queue<int> pq; \n priority_queue<int, vector<int>, greater<int>> mh;\n for(int i = 0; i < nums.size(); i++) {\n pq.push(nums[i]);\n mh.push(nums[i]);\n } \n int mn = pq.top() - mh.t... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n multiset<int>st;\n int n=nums.size();\n for(int i=0;i<n;i++)\n { if(nums[i]%2==0)\n st.insert(nums[i]);\n else st.insert(2*nums[i]);\n }\n int ans=INT_MAX;\n wh... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) { \n set<int> s;\n for(auto i: nums) s.insert(i); //insert everything into a set\n int dev= *s.rbegin()-*s.begin(); //difference between max and min\n for(auto i: nums) if(i&1){ s.erase(i);s.insert(i<<=1);}... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n vector<vector<int>> v;\n for(int i=0;i<nums.size();i++){\n vector<int> cur;\n if(nums[i]%2==0){\n int x=nums[i];\n while(x%2==0){\n cur.push_back(x... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n int maxi=INT_MIN;\n int mini=INT_MAX;\n \n int n=nums.size();\n multiset<int> s;\n for(auto e:nums)\n s.insert(e);\n int diff=*(--s.end())-*s.begin();\n while((*s.be... |
1,794 | <p>You are given an array <code>nums</code> of <code>n</code> positive integers.</p>
<p>You can perform two types of operations on any element of the array any number of times:</p>
<ul>
<li>If the element is <strong>even</strong>, <strong>divide</strong> it by <code>2</code>.
<ul>
<li>For example, if the array i... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeviation(vector<int>& nums) {\n set<pair<int,int>>s;\n for(int i=0;i<nums.size();i++)\n {\n int x=nums[i];\n while(x%2==0)\n x/=2;\n s.insert({x,i});\n }\n int ans=(*prev(s.end())).... |
1,798 | <p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p>
<p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p>
<p>Return <em>the maximum number of operations you can perform on the array</em>.</p>
<p> </p>
<... | 0 | {
"code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int n=nums.size();\n int i=0, j=n-1;\n int c=0;\n sort(nums.begin(),nums.end());\n while(i<j){\n if(nums[i]+nums[j]==k){\n c++;i++;j--;\n }\n els... |
1,798 | <p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p>
<p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p>
<p>Return <em>the maximum number of operations you can perform on the array</em>.</p>
<p> </p>
<... | 0 | {
"code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n int i=0;\n int j=n-1;\n int cnt=0;\n while(i<j){\n int sum=nums[i]+nums[j];\n if(sum==k){\n i++... |
1,798 | <p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p>
<p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p>
<p>Return <em>the maximum number of operations you can perform on the array</em>.</p>
<p> </p>
<... | 0 | {
"code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end()); // Sort the array first\n int left = 0;\n int right = nums.size() - 1;\n int count = 0;\n\n while (left < right) {\n int sum = nums[left] + nums[right... |
1,798 | <p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p>
<p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p>
<p>Return <em>the maximum number of operations you can perform on the array</em>.</p>
<p> </p>
<... | 0 | {
"code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n int i=0,j=n-1;\n int c=0;\n while(i<j){\n int y=nums[i]+nums[j];\n if(y == k){\n c++;\n ... |
1,798 | <p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p>
<p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p>
<p>Return <em>the maximum number of operations you can perform on the array</em>.</p>
<p> </p>
<... | 0 | {
"code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int cnt=0;\n sort(nums.begin(),nums.end());\n int j=nums.size()-1,i=0;\n while(i<j){\n if(nums[i]+nums[j]==k){\n cnt++;\n j--;\n i++;\n ... |
1,798 | <p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p>
<p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p>
<p>Return <em>the maximum number of operations you can perform on the array</em>.</p>
<p> </p>
<... | 0 | {
"code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int i=0,j=nums.size()-1,count=0;\n sort(nums.begin(),nums.end());\n while(i<j){\n if(nums[i]+nums[j]==k){\n i++;j--;count++;\n }\n else if(nums[i]+nums[j]<k){\... |
1,798 | <p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p>
<p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p>
<p>Return <em>the maximum number of operations you can perform on the array</em>.</p>
<p> </p>
<... | 1 | {
"code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n int count = 0;\n int left = 0, right = nums.size()-1;\n while(right>left){\n \n if(nums[right] + nums[left] == k){\n left++;\n ... |
1,798 | <p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p>
<p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p>
<p>Return <em>the maximum number of operations you can perform on the array</em>.</p>
<p> </p>
<... | 1 | {
"code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int cnt=0;\n sort(nums.begin(),nums.end());\n int j=nums.size()-1,i=0;\n while(i<j){\n if(nums[i]+nums[j]==k){\n cnt++;\n j--;\n i++;\n ... |
1,798 | <p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p>
<p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p>
<p>Return <em>the maximum number of operations you can perform on the array</em>.</p>
<p> </p>
<... | 2 | {
"code": "class Solution {\n //https://leetcode.com/problems/max-number-of-k-sum-pairs/solutions/5653907/easy-c-solution-sorting-binary-search\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n int low=0,high=n-1;\n int c... |
1,798 | <p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p>
<p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p>
<p>Return <em>the maximum number of operations you can perform on the array</em>.</p>
<p> </p>
<... | 2 | {
"code": "\nclass Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int n=nums.size();\n int i=0,j=n-1;\n int c=0;\n sort(nums.begin(),nums.end());\n while(i<j)\n {\n if(nums[i]+nums[j]==k){ c++; i++;j--;}\n else if(nums[i]+ nums[... |
1,798 | <p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p>
<p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p>
<p>Return <em>the maximum number of operations you can perform on the array</em>.</p>
<p> </p>
<... | 2 | {
"code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int n = nums.size();\n vector<bool> used(n,false);\n int op = 0;\n int i = 0;\n int j = nums.size()-1;\n \n sort(nums.begin(), nums.end());\n while(i < j){\n int... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.