-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3349.cpp
More file actions
25 lines (25 loc) · 714 Bytes
/
3349.cpp
File metadata and controls
25 lines (25 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution {
public:
bool hasIncreasingSubarrays(vector<int>& nums, int k) {
int n = nums.size();
vector<int> counts(n, 0);
int cnt = 0;
int current = INT_MAX;
for (int i = 0; i < n; ++i) {
if (nums[i] > current) cnt++;
else {
cnt = 1;
}
current = nums[i];
counts[i] = cnt;
}
for (int i = 0; i < n; ++i) {
int end1 = i + k - 1;
int end2 = i + 2 * k - 1;
if (end2 >= n) break;
if (counts[end1] >= k && counts[end2] >= k) return true;
if (counts[end2] >= 2 * k) return true;
}
return false;
}
};