See code (Must first up and then down)
O(n) O(1)
class Solution:
def longestMountain(self, A):
"""
:type A: List[int]
:rtype: int
"""
up = down = res = 0
for i in range(len(A) - 1):
if down and A[i + 1] > A[i] or A[i + 1] == A[i]:
up = down = 0
up += A[i + 1] > A[i]
down += A[i + 1] < A[i]
if up and down: res = max(res, up + down + 1)
return res