← 返回 google 的题目列表Find the Longest Increasing Subarray with Replacement Option
类型:online_judge
Given an array, find the longest strictly increasing continuous subarray. For the follow-up, if we allow replacing one element in each subarray, determine the longest possible increasing subarray by making at most one replacement. Return the length of that subarray.
Input:
An integer array of length n, where 1 ≤ n ≤ 10^5 and elements are in the range of -10^9 to 10^9
Output:
The length of the longest possible increasing subarray with at most one replacement.
Example 1: Input: [1, 3, 5, 4, 7] Output: 4 Explanation: Replace 4 with 6 to get the subarray [1, 3, 5, 6]
Example 2: Input: [2, 2, 2, 2, 2] Output: 2
Example
Input
1 3 5 4 6