Skip to content

Commit 466db05

Browse files
committed
Add solution #3349
1 parent 37d1314 commit 466db05

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,6 +2712,7 @@
27122712
3342|[Find Minimum Time to Reach Last Room II](./solutions/3342-find-minimum-time-to-reach-last-room-ii.js)|Medium|
27132713
3343|[Count Number of Balanced Permutations](./solutions/3343-count-number-of-balanced-permutations.js)|Hard|
27142714
3344|[Maximum Sized Array](./solutions/3344-maximum-sized-array.js)|Medium|
2715+
3349|[Adjacent Increasing Subarrays Detection I](./solutions/3349-adjacent-increasing-subarrays-detection-i.js)|Easy|
27152716
3353|[Minimum Total Operations](./solutions/3353-minimum-total-operations.js)|Easy|
27162717
3355|[Zero Array Transformation I](./solutions/3355-zero-array-transformation-i.js)|Medium|
27172718
3356|[Zero Array Transformation II](./solutions/3356-zero-array-transformation-ii.js)|Medium|
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* 3349. Adjacent Increasing Subarrays Detection I
3+
* https://leetcode.com/problems/adjacent-increasing-subarrays-detection-i/
4+
* Difficulty: Easy
5+
*
6+
* Given an array nums of n integers and an integer k, determine whether there exist two
7+
* adjacent subarrays of length k such that both subarrays are strictly increasing.
8+
* Specifically, check if there are two subarrays starting at indices a and b (a < b),
9+
* where:
10+
* - Both subarrays nums[a..a + k - 1] and nums[b..b + k - 1] are strictly increasing.
11+
* - The subarrays must be adjacent, meaning b = a + k.
12+
*
13+
* Return true if it is possible to find two such subarrays, and false otherwise.
14+
*/
15+
16+
/**
17+
* @param {number[]} nums
18+
* @param {number} k
19+
* @return {boolean}
20+
*/
21+
var hasIncreasingSubarrays = function(nums, k) {
22+
for (let i = 0; i <= nums.length - 2 * k; i++) {
23+
if (helper(i, k) && helper(i + k, k)) {
24+
return true;
25+
}
26+
}
27+
28+
return false;
29+
30+
function helper(start, length) {
31+
for (let i = start; i < start + length - 1; i++) {
32+
if (nums[i] >= nums[i + 1]) return false;
33+
}
34+
return true;
35+
}
36+
};

0 commit comments

Comments
 (0)