Problems > Longest Mountain > Editorial

Longest Mountain — Solution & Editorial

Back to the Problem

Scan for peaks (ai−1 < ai > ai+1); expand left while strictly rising and right while strictly falling; skip the whole mountain afterward for O(N).

Complexity: O(N)