Skip to content

Commit 154527e

Browse files
authored
Create 3349-adjacent-increasing-subarrays-detection-i.js
1 parent 2dc3c96 commit 154527e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number} k
4+
* @return {boolean}
5+
*/
6+
var hasIncreasingSubarrays = function (nums, k) {
7+
const n = nums.length
8+
9+
for (let i = 0; i <= n - 2 * k; ++i) {
10+
let firstIncreasing = true
11+
let secondIncreasing = true
12+
13+
for (let j = i; j < i + k - 1; ++j) {
14+
if (nums[j] >= nums[j + 1]) {
15+
firstIncreasing = false
16+
break
17+
}
18+
}
19+
20+
if (!firstIncreasing) continue
21+
22+
for (let j = i + k; j < i + 2 * k - 1; ++j) {
23+
if (nums[j] >= nums[j + 1]) {
24+
secondIncreasing = false
25+
break
26+
}
27+
}
28+
29+
if (firstIncreasing && secondIncreasing) return true
30+
}
31+
32+
return false
33+
}

0 commit comments

Comments
 (0)