nikunjsoni

1673

Apr 3rd, 2021
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     vector<int> mostCompetitive(vector<int>& nums, int k) {
  4.         vector<int> s;
  5.         int sz = nums.size();
  6.         for(int i=0; i<sz; i++){
  7.             while(!s.empty() && s.back() > nums[i] && (s.size()-1+sz-i)>=k)
  8.                 s.pop_back();
  9.              if(s.size() < k) s.push_back(nums[i]);
  10.         }
  11.         return s;
  12.     }
  13. };
RAW Paste Data