[InterviewBit] Longest Increasing Subsequence

Longest Increasing Subsequence

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
int Solution::lis(const vector<int> &A) {
vector<int> dp;
for(auto& a : A) {
auto lb = lower_bound(begin(dp), end(dp), a);
if(lb == end(dp)) dp.push_back(a);
else *lb = a;
}
return dp.size();
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/09/PS/interviewbit/longest-increasing-subsequence/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.