Determine whether an array contains two adjacent strictly increasing subarrays of a given length.
Problem
Given an integer array nums and an integer k, determine whether there exist two adjacent subarrays of length k such that:
- the first subarray is strictly increasing,
- the second subarray is also strictly increasing,
- the second subarray starts immediately after the first one ends.
In other words, you are looking for a contiguous segment of length 2k where both halves of length k are strictly increasing.
Return true if such a pair exists, otherwise return false.
Notes
- A subarray is a contiguous part of the array.
- A strictly increasing subarray means every element is greater than the previous one.
Input Format
- An integer array
nums. - An integer
k.
Output Format
- Return a boolean value indicating whether the required adjacent increasing subarrays exist.
Input Format
nums: integer arrayk: positive integer
Output Format
- Return
trueif there are two adjacent strictly increasing subarrays of lengthk; otherwise returnfalse.
Constraints
1 <= k <= nums.length / 2numscontains integers- The array length is at least
2k
Example 1
Input
nums = [1,2,3,1,2,3], k = 3
Output
true
Explanation
The subarray [1,2,3] is strictly increasing, and the adjacent subarray [1,2,3] is also strictly increasing.
Example 2
Input
nums = [1,2,1,2,3], k = 2
Output
true
Explanation
The subarrays [1,2] and [1,2] at positions [0..1] and [2..3] are adjacent and both strictly increasing.
Show 1 more example
Example 3
Input
nums = [5,4,3,2,1], k = 2
Output
false
Explanation
There is no pair of adjacent subarrays of length 2 that are both strictly increasing.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.