-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
36 lines (32 loc) · 859 Bytes
/
test.py
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
26
27
28
29
30
31
32
33
34
35
36
#!/bin/python3
import sys
def minimumDeletions(a):
# Complete this function
deletions = 0
lastX = None
trend = 0
for x in a:
deleteX = False
if lastX:
if lastX < x:
if trend > 0 and trend == 1:
deleteX = True
else:
trend = 1
elif lastX > x:
if trend < 0 and trend == -1:
deleteX = True
else:
trend = -1
else:
trend = 0
if deleteX:
deletions = deletions + 1
else:
lastX = x
return deletions
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
# Return the minimum number of elements to delete to make the array zigzag
result = minimumDeletions(a)
print(result)