-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_outer_to_inner_is_asc.py
57 lines (47 loc) · 1.37 KB
/
list_outer_to_inner_is_asc.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
"""
Can alternating array be sorted strictly ascending?
all tests passed.
"""
def solution(a):
# print(a)
if len(a) <=1:
return(True)
L=0
R=len(a)-1
while L<=R:
# print(f"a[L]:{a[L]}")
# print(f"a[R]:{a[R]}")
# print(f"`{a[L]}` < `{a[R]}` :{a[L] < a[R]}")
if a[L] == a[R]:
# if equal check if they are accessing same ix
# check if it is middle
if len(a)%2==1:
if L+1 == len(a)//2+1:
# print(f"middle at L:{L}, len(a):{len(a)}")
if a[L]>a[R+1]:
# print(f"curr `{a[L]}` greater than last `{a[R+1]}` ")
return(True)
else:
return(False)
else:
return(False)
if not a[L] < a[R]:
return(False)
if R<len(a)-1:
if a[L] == a[R+1]:
return(False)
# if
L+=1
R-=1
return(True)
"""
Your task is to determine whether the new array b is sorted in strictly ascending order or not
we can compare with out actually making new list
a = [1, 3, 5, 6, 4, 2]
L R
True
L R
True
L R
True
"""