Adjacent Increasing Subarrays Detection I - Problem
Given an array nums of n integers and an integer k, determine whether there exist two adjacent subarrays of length k such that both subarrays are strictly increasing.
Specifically, check if there are two subarrays 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 true if it is possible to find two such subarrays, and false otherwise.
Input & Output
Example 1 — Basic Valid Case
$
Input:
nums = [1,2,3,4,5], k = 2
›
Output:
true
💡 Note:
Subarrays [1,2] at index 0 and [2,3] at index 1 are adjacent. [1,2]: 2 > 1 ✓ (strictly increasing). [2,3]: 3 > 2 ✓ (strictly increasing). Both adjacent subarrays are strictly increasing.
Example 2 — Valid Adjacent Increasing Subarrays
$
Input:
nums = [1,2,3,4,5], k = 2
›
Output:
true
💡 Note:
Subarrays [1,2] at index 0 and [2,3] at index 1 are adjacent. [1,2]: 2 > 1 ✓ (strictly increasing). [2,3]: 3 > 2 ✓ (strictly increasing). Both adjacent subarrays are strictly increasing.
Example 3 — No Valid Adjacent Pairs
$
Input:
nums = [1,3,2,4], k = 2
›
Output:
false
💡 Note:
Position 0: [1,3] (increasing) + [3,2] (decreasing) = false. Position 1: [3,2] (decreasing) + [2,4] (increasing) = false. No adjacent pair of increasing subarrays exists.
Constraints
- 2 ≤ nums.length ≤ 100
- 1 ≤ k ≤ nums.length / 2
- -100 ≤ nums[i] ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code