nikunjsoni

1964

Aug 15th, 2021
946
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     vector<int> longestObstacleCourseAtEachPosition(vector<int>& obs) {
  4.         vector<int> seq;
  5.         vector<int> ans;
  6.         for(auto num: obs){
  7.             auto it = upper_bound(seq.begin(), seq.end(), num)-seq.begin();
  8.             if(it == seq.size()){
  9.                 seq.push_back(num);
  10.                 ans.push_back(seq.size());
  11.                 continue;
  12.             }
  13.             seq[it] = num;
  14.             ans.push_back(it+1);
  15.         }
  16.         return ans;
  17.     }
  18. };
RAW Paste Data