Search
⌘K

Leetcode 2765. Longest Alternating Subarray

Find the longest contiguous subarray (length > 1) whose consecutive differences alternate +1, -1, +1, ... — i.e., each element toggles between prev+1 and prev-1 starting with +1. Return its length or -1 if no such subarray exists.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.