Back to problems

Longest Non-Decreasing Subarray with One Replacement

Algorithm · Google · Medium

You are given an integer array nums. You are allowed to overwrite at most one element with any value of your choosing. After making that optional change, look for the longest contiguous subarray that is non-decreasing, meaning nums[i] <= nums[i + 1] holds for every adjacent pair inside it. Return the length of the longest such subarray you can obtain. Example 1: Follow-ups Variant: other rounds ask for a strictly increasing run instead. These rounds start with the version…

Loading the rest of the question…