Skip to content

Commit 86c3f68

Browse files
authored
Create minimum-number-of-increasing-subsequence-to-be-removed.cpp
1 parent cd1c1d9 commit 86c3f68

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Time: O(nlogn)
2+
// Space: O(n)
3+
4+
// binary search, longest increasing subsequence, lis
5+
class Solution {
6+
public:
7+
int minOperations(vector<int>& nums) {
8+
const auto& longest_non_increasing_subsequence = [](const auto& arr) {
9+
vector<int> result;
10+
for (const auto& x : arr) {
11+
auto it = upper_bound(begin(result), end(result), -x);
12+
if (it == end(result)) {
13+
result.emplace_back(-x);
14+
} else {
15+
*it = -x;
16+
}
17+
}
18+
return size(result);
19+
};
20+
21+
return longest_non_increasing_subsequence(nums);
22+
}
23+
};

0 commit comments

Comments
 (0)