Longest Alternating Subarray After One Deletion
Problem statement
You are given an integer array nums. Choose a contiguous segment of the original array, then delete at most one element from that segment. The remaining elements keep their original order.
The remaining sequence is alternating when every adjacent comparison is strict and its direction alternates: greater, less, greater, less, or less, greater, less, greater. Equal adjacent elements break alternation. A sequence of length 0 or 1 is alternating.
Examples
Example 1
nums = [1,3,2,2,4,1]return = 5Delete one of the adjacent 2s. The entire segment becomes [1,3,2,4,1], whose comparisons alternate.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.