#3830
Longest Alternating Subarray After Removing At Most One Element
international master · 1975 · lc hard +32 · 30.4% accepted · 68 likes · top 8%
Description
Given an integer array nums, a subarray nums[l..r] is alternating if adjacent comparisons strictly alternate direction — either nums[l] < nums[l+1] > nums[l+2] < ... or nums[l] > nums[l+1] < nums[l+2] > .... You may remove at most one element from nums, then select an alternating subarray from the result. Return the maximum possible length of such a subarray. A single-element subarray is always considered alternating.
Code
1
2
3