-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 10
More file actions
25 lines (19 loc) · 733 Bytes
/
Day 10
File metadata and controls
25 lines (19 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
##3350.adjacent-increasing-subarrays-detection-ii
class Solution:
def maxIncreasingSubarrays(self, nums: List[int]) -> int:
n = len(nums)
left = [1] * n
right = [1] * n
# Increasing streak ending at each index
for i in range(1, n):
if nums[i] > nums[i - 1]:
left[i] = left[i - 1] + 1
# Increasing streak starting at each index
for i in range(n - 2, -1, -1):
if nums[i] < nums[i + 1]:
right[i] = right[i + 1] + 1
# Find max possible k
max_k = 0
for i in range(n - 1):
max_k = max(max_k, min(left[i], right[i + 1]))
return max_k