Adjacent Increasing Subarrays Detection II - Problem
Given an array nums of n integers, your task is to find the maximum value of k for which there exist two adjacent subarrays of length k each, such that both subarrays are strictly increasing.
Specifically, check if there are two subarrays of length k starting at indices a and b (a < b), where:
- Both subarrays
nums[a..a + k - 1]andnums[b..b + k - 1]are strictly increasing. - The subarrays must be adjacent, meaning
b = a + k.
Return the maximum possible value of k. A subarray is a contiguous non-empty sequence of elements within an array.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [2,5,7,8,9,2,3,4,3,1]
›
Output:
1
💡 Note:
We can find adjacent increasing subarrays of length 1, for example [2] at index 0 and [5] at index 1, both strictly increasing.
Example 2 — No Adjacent Pairs
$
Input:
nums = [1,2,3,2,1]
›
Output:
1
💡 Note:
We can find adjacent increasing subarrays of length 1, for example [1] at index 0 and [2] at index 1, both strictly increasing.
Example 3 — Small Array
$
Input:
nums = [1,2]
›
Output:
0
💡 Note:
Array is too small to have two adjacent subarrays of any positive length.
Constraints
- 2 ≤ nums.length ≤ 105
- 1 ≤ nums[i] ≤ 109
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code