Skip to content

Commit 2fae1d2

Browse files
committed
2210. Count Hills and Valleys in an Array
1 parent 3aa8fa8 commit 2fae1d2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def countHillValley(nums):
2+
n = len(nums)
3+
i = 1
4+
count = 0
5+
while i < n - 1:
6+
left = i - 1
7+
while left >= 0 and nums[left] == nums[i]:
8+
left -= 1
9+
right = i + 1
10+
while right < n and nums[right] == nums[i]:
11+
right += 1
12+
if left >= 0 and right < n:
13+
if nums[left] < nums[i] and nums[right] < nums[i]:
14+
count += 1
15+
elif nums[left] > nums[i] and nums[right] > nums[i]:
16+
count += 1
17+
i = right
18+
return count
19+
20+
21+
arr = list(map(int, input("enter the array: ").split(",")))
22+
print(countHillValley(arr))

leet code/3487. Maximum Unique Subarray Sum After Deletion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ def maxSum(nums):
1212
return total_data
1313

1414

15-
arr = list(map(int, input("Enter the array:").split(',')))
15+
arr = list(map(int, input("Enter the array:").split(",")))
1616
print(maxSum(arr))

0 commit comments

Comments
 (0)