Skip to content

Commit 5eaf013

Browse files
authored
Create Adjacent Increasing Subarrays Detection I.java
1 parent ceb871f commit 5eaf013

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public boolean hasIncreasingSubarrays(List<Integer> nums, int k) {
3+
int n = nums.size();
4+
for (int i = 0; i <= n - 2 * k; i++) {
5+
if (isStrictlyIncreasing(nums, i, k) && isStrictlyIncreasing(nums, i + k, k)) {
6+
return true;
7+
}
8+
}
9+
return false;
10+
}
11+
12+
private boolean isStrictlyIncreasing(List<Integer> nums, int idx, int k) {
13+
for (int start = idx; start < idx + k - 1; start++) {
14+
if (nums.get(start) >= nums.get(start + 1)) {
15+
return false;
16+
}
17+
}
18+
return true;
19+
}
20+
}

0 commit comments

Comments
 (0)