https://leetcode.com/problems/longest-mountain-in-array/?envType=problem-list-v2&envId=dynamic-programming&difficulty=MEDIUM
class Solution:
def longestMountain(self, arr: List[int]) -> int:
n = len(arr)
ans = base = 0
while base < n:
end = base
# if base is a left boundary
if end + 1 < n and arr[end] < arr[end+1]:
# set end to the peak of this potential mountain
while end+1 < n and arr[end] < arr[end+1]:
end += 1
# if end is really a peak
if end+1 < n and arr[end] > arr[end+1]:
# set end to right boundary of mountain
while end+1 < n and arr[end] > arr[end+1]:
end += 1
# record candidate answer
ans = max(ans, end - base + 1)
base = max(end, base+1)
return ans