-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPiling Up.py
39 lines (37 loc) · 932 Bytes
/
Piling Up.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
'''
Problem Statement: https://www.hackerrank.com/challenges/piling-up/problem
@Coded by TSG, 2020
'''
from collections import deque
for _ in range(int(input())):
flag = True
input()
d = deque(map(int, input().strip().split()))
if (d[0] >= d[-1]):
max = d.popleft()
else:
max = d.pop()
while d:
if (len(d) == 1):
if (d[0] <= max):
break
else:
flag = False
break;
else:
if d[0] <= max and d[-1] <= max:
if d[0] >= d[-1]:
max = d.popleft()
else:
max = d.pop()
elif d[0] <= max:
max = d.popleft()
elif d[-1] <= max:
max = d.pop()
else:
flag = False
break;
if flag:
print ("Yes")
else:
print ("No")