Problem 978 · Medium

Longest Turbulent Subarray

Find the longest contiguous stretch in which neighbouring values keep alternating between rising and falling. The visual shows the direction of each step as a sign that flips with every comparison.

Open the interactive visualisation