We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 40273ac commit edc4eecCopy full SHA for edc4eec
python/0978-longest-turbulent-subarray.py
@@ -0,0 +1,19 @@
1
+class Solution:
2
+ def maxTurbulenceSize(self, arr: List[int]) -> int:
3
+ l, r = 0, 1
4
+ res, prev = 1, ""
5
+
6
+ while r < len(arr):
7
+ if arr[r - 1] > arr[r] and prev != ">":
8
+ res = max(res, r - l + 1)
9
+ r += 1
10
+ prev = ">"
11
+ elif arr[r - 1] < arr[r] and prev != "<":
12
13
14
+ prev = "<"
15
+ else:
16
+ r = r + 1 if arr[r] == arr[r - 1] else r
17
+ l = r - 1
18
+ prev = ""
19
+ return res
0 commit comments