Problem 4017 · Medium

Peaks in Array II

Keep a peak flag per position, updated after each point change. A range query sweeps left from its right end, tracking the nearest peak to the right, and counts every subarray that reaches it.

Open the interactive visualisation