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.
T = int(input())
for j in range(T):
n = int(input())
blocks = list(map(int, input().split()))
result = True
left, right = 0, n-1
top = float('inf')
while left <= right:
if blocks[left] <= top and (blocks[left] >= blocks[right]):
top = blocks[left]
left += 1
elif blocks[right] <= top:
top = blocks[right]
right -= 1
else:
result = False
break
print("Yes" if result else "No")
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 →
T = int(input()) for j in range(T): n = int(input()) blocks = list(map(int, input().split())) result = True left, right = 0, n-1 top = float('inf') while left <= right: if blocks[left] <= top and (blocks[left] >= blocks[right]): top = blocks[left] left += 1 elif blocks[right] <= top: top = blocks[right] right -= 1 else: result = False break