We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import deque
num_of_tests = int(input())
for ntest in range(num_of_tests):
# read number of blocks
num_of_blocks = int(input())
# read block sizes
blocks = deque(map(int,input().strip().split()))
# put down largest block from left/right
if blocks[0] >= blocks[-1]:
base_block = blocks[0]
blocks.popleft()
else:
base_block = blocks[-1]
blocks.pop()
# See if the rest can be stacked
result = "Yes"
while blocks:
left_block = blocks[0]
right_block = blocks[-1]
if left_block >= right_block:
current_block = left_block
blocks.popleft()
else:
current_block = right_block
blocks.pop()
if current_block <= base_block:
base_block = current_block
else:
result = "No"
break
print(result)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Piling Up!
You are viewing a single comment's thread. Return to all comments →
Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import deque
num_of_tests = int(input())
for ntest in range(num_of_tests): # read number of blocks num_of_blocks = int(input())