-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathincreasing-sequence.py
90 lines (78 loc) · 2.72 KB
/
increasing-sequence.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def almostIncreasingSequence(sequence):
index=1
count=0
if len(sequence)==1:
return sequence
while index <= (len(sequence)-1):
if index < len(sequence)-1:
previous=sequence[index-1]
current=sequence[index]
next=sequence[index+1]
stop_here=index+1
if index == len(sequence)-1:
previous=sequence[index-1]
current=sequence[index]
next = max(sequence)+200
stop_here=index
if previous < current < next:
index+=2
if index <= len(sequence)-1:
if next>sequence[index] and current>sequence[index]:
return False
elif previous > current > next:
return False
elif previous==current==next:
return False
elif previous>current and current==next:
return False
elif previous==current and current>next:
return False
elif previous>current and current<next:
count+=1
index+=2
elif previous==current and current<next:
count+=1
index+=2
elif previous<current and current==next:
count+=1
index+=2
elif previous<current and current>next and previous<next:
count+=1
index+=2
elif previous<current and current>next and previous==next:
count+=1
if len(sequence)-1 >= index+3:
if current<sequence[index+2]:
index+=3
else:
return False
elif len(sequence)-1 == index+2:
if current>= sequence[len(sequence)-1]:
return False
else:
return True
elif previous<current and current>next and previous>next:
count+=1
if len(sequence)-1 >= index+3:
if current<sequence[index+2]:
index+=3
else:
return False
elif len(sequence)-1 == index+2:
if current>= sequence[len(sequence)-1]:
return False
else:
return True
else:
if current<= sequence[len(sequence)-1]:
return False
else:
return True
if count>1:
return False
if stop_here==len(sequence)-1:
if count>1:
return False
else:
return True
return True