You are viewing a single comment's thread. Return to all comments →
T = int(input()) def is_stackable(cubes): expected_stack = sorted(cubes) left, right = 0, len(cubes) - 1 while len(expected_stack) > 0: expected_block = expected_stack.pop() if cubes[left] == expected_block: left += 1 elif cubes[right] == expected_block: right -= 1 else: return False return True for t in range(T): n = int(input()) cubes = list(map(int, input().split())) print("Yes" if is_stackable(cubes) else "No")
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 →