Skip to content

Commit 42624ca

Browse files
authored
Create divide-array-into-increasing-sequences.cpp
1 parent bf49997 commit 42624ca

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
bool canDivideIntoSubsequences(vector<int>& nums, int K) {
7+
int curr = 1, max_count = 1;
8+
for (int i = 1; i < nums.size(); ++i) {
9+
curr = (nums[i - 1] < nums[i]) ? 1 : curr + 1;
10+
max_count = max(max_count, curr);
11+
}
12+
return K * max_count <= nums.size();
13+
}
14+
};

0 commit comments

Comments
 (0)