forked from arsho/Hackerrank_Python_Domain_Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPilingUp.py
31 lines (29 loc) · 794 Bytes
/
PilingUp.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
"""
Title : Piling Up!
Subdomain : Collections
Domain : Python
Author : Ahmedur Rahman Shovon
Created : 15 July 2016
Problem : https://www.hackerrank.com/challenges/piling-up/problem
"""
from collections import deque
cas = int(input())
for _ in range(cas):
n = int(input())
dq = deque(map(int, input().split()))
possible = True
element = (2**31) + 1
while dq:
left_element = dq[0]
right_element = dq[-1]
if left_element >= right_element and element >= left_element:
element = dq.popleft()
elif right_element >= left_element and element >= right_element:
element = dq.pop()
else:
possible = False
break
if possible:
print("Yes")
else:
print("No")