We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a4c7d77 commit 3f47068Copy full SHA for 3f47068
1 file changed
Longest_mountain_array
@@ -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