Practice/Google/Leetcode 3350. Adjacent Increasing Subarrays Detection II
CodingOptional
You are given an array of integers. Your task is to find the maximum length k such that there exist two adjacent subarrays (one immediately following the other with no gap) where:
Return the maximum value of k that satisfies these conditions.
Example 1:
Input: nums = [1, 2, 3, 4, 2, 3, 4, 5] Output: 3 Explanation: The subarray [1,2,3] (indices 0-2) and [4,2,3] starting at index 3... wait, that's not increasing. Let's check [2,3,4] (indices 4-6) and [4,5,...] - no that overlaps. Actually, [1,2,3] at indices 0-2 is not followed by another length-3 increasing array. The correct split is trickier - we need to analyze the maximal increasing runs carefully.
Example 2:
Input: nums = [1, 2, 3, 4, 5, 6] Output: 3 Explanation: We can use [1,2,3] (indices 0-2) and [4,5,6] (indices 3-5). Both are strictly increasing with length 3.
Example 3:
Input: nums = [5, 4, 3, 2, 1] Output: 1 Explanation: The array is decreasing, so no two adjacent elements are increasing. However, each single element is trivially a strictly increasing sequence of length 1, so k=1 is the answer.
Example 4:
Input: nums = [1, 2, 1, 2, 1, 2] Output: 1 Explanation: Only single-element subarrays work, so k=1.