Skip to content

Commit fdca9a4

Browse files
committed
Add solution #3350
1 parent 6a5e066 commit fdca9a4

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,6 +2713,7 @@
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|
27152715
3349|[Adjacent Increasing Subarrays Detection I](./solutions/3349-adjacent-increasing-subarrays-detection-i.js)|Easy|
2716+
3350|[Adjacent Increasing Subarrays Detection II](./solutions/3350-adjacent-increasing-subarrays-detection-ii.js)|Medium|
27162717
3353|[Minimum Total Operations](./solutions/3353-minimum-total-operations.js)|Easy|
27172718
3355|[Zero Array Transformation I](./solutions/3355-zero-array-transformation-i.js)|Medium|
27182719
3356|[Zero Array Transformation II](./solutions/3356-zero-array-transformation-ii.js)|Medium|
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* 3350. Adjacent Increasing Subarrays Detection II
3+
* https://leetcode.com/problems/adjacent-increasing-subarrays-detection-ii/
4+
* Difficulty: Medium
5+
*
6+
* Given an array nums of n integers, your task is to find the maximum value of k for which
7+
* there exist two adjacent subarrays of length k each, such that both subarrays are strictly
8+
* increasing. Specifically, check if there are two subarrays of length k starting at indices
9+
* a and b (a < b), 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 the maximum possible value of k.
14+
*
15+
* A subarray is a contiguous non-empty sequence of elements within an array.
16+
*/
17+
18+
/**
19+
* @param {number[]} nums
20+
* @return {number}
21+
*/
22+
var maxIncreasingSubarrays = function(nums) {
23+
const n = nums.length;
24+
const lengths = new Array(n).fill(1);
25+
26+
for (let i = n - 2; i >= 0; i--) {
27+
if (nums[i] < nums[i + 1]) {
28+
lengths[i] = lengths[i + 1] + 1;
29+
}
30+
}
31+
32+
let result = 0;
33+
for (let i = 0; i < n; i++) {
34+
const currentLength = lengths[i];
35+
result = Math.max(result, Math.floor(currentLength / 2));
36+
37+
const nextIndex = i + currentLength;
38+
if (nextIndex < n) {
39+
const minLength = Math.min(currentLength, lengths[nextIndex]);
40+
result = Math.max(result, minLength);
41+
}
42+
}
43+
44+
return result;
45+
};

0 commit comments

Comments
 (0)