Two Non-Overlapping Increasing Blocks
Problem statement
A block is a run of consecutive positions of nums. It is increasing when every value is strictly larger than the one before it (a block of one value counts as increasing). Two blocks do not overlap when no position belongs to both; they do not have to be next to each other.
Return [fitsK, best], where:
fitsKis1ifnumshas two non-overlapping increasing blocks of lengthk, otherwise0;bestis the largest lengthLfor whichnumshas two non-overlapping increasing blocks of lengthL.
Function
twoIncreasingBlocks(nums: int[], k: int) → int[]Examples
Example 1
nums = [1,3,5,2,4,6,8,0]k = 3return = [1,3][1, 3, 5] (positions 0 to 2) and [2, 4, 6] (positions 3 to 5) are both increasing and share no position, so length 3 works. Length 4 fails: the only increasing block of 4 is [2, 4, 6, 8], and nothing else of length 4 is increasing. So the answer is [1, 3].
Example 2
nums = [5,6,7,8,9,10,11]k = 4return = [0,3]The whole array increases, but two blocks of 4 need 8 positions and there are only 7. Splitting it gives two blocks of 3, for example [5, 6, 7] and [8, 9, 10]. The answer is [0, 3].
Example 3
nums = [4,4,4]k = 1return = [1,1]Equal neighbours are not increasing, so no block longer than 1 works. Any single value counts as increasing, and two single values never overlap: [1, 1].
Constraints
2 <= nums.length <= 20000-10^9 <= nums[i] <= 10^91 <= k <= nums.length