Skip to content

Commit 3f47068

Browse files
authored
Longest_mountain_array
Initial File
1 parent a4c7d77 commit 3f47068

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Longest_mountain_array

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def longestmountain(A):
2+
peaks = {}
3+
for i in range(1,len(A)-1):
4+
if A[i] > A[i-1] and A[i] > A[i+1]:
5+
peaks[i] = A[i]
6+
7+
left = 0
8+
right = 0
9+
val = 0
10+
11+
for i, j in peaks.items():
12+
left = i-1
13+
while left > 0 and A[left -1] < A[left]:
14+
left = left - 1
15+
16+
right = i+1
17+
while right < len(A)-1 and A[right] > A[right+1]:
18+
right = right + 1
19+
20+
val = max(val, right-left+1)
21+
return val
22+
23+
B=[10,15,16,9,4,3,11,1]
24+
print(longestmountain(B))
25+

0 commit comments

Comments
 (0)