-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
41 lines (37 loc) · 1.03 KB
/
solution.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
37
38
39
40
41
STATE_ANY = 0
STATE_ASCENDING = 1
STATE_DESCENDING = 2
input()
numbers = list(map(int, input().split()))
prev = None
state = STATE_ANY
current_length = 0
last_any_length = 0
longest_length = 0
for i in numbers:
if prev is None:
prev = i
current_length = 1
continue
if prev < i:
if state == STATE_ASCENDING or state == STATE_ANY:
current_length += 1
else:
longest_length = max(longest_length, current_length)
current_length = 2 + last_any_length - 1
last_any_length = 1
state = STATE_ASCENDING
elif prev > i:
if state == STATE_DESCENDING or state == STATE_ANY:
current_length += 1
else:
longest_length = max(longest_length, current_length)
current_length = 2 + last_any_length - 1
last_any_length = 1
state = STATE_DESCENDING
else:
current_length += 1
last_any_length += 1
prev = i
longest_length = max(longest_length, current_length)
print(longest_length)