You are viewing a single comment's thread. Return to all comments →
def can_stack_cubes(cubes): last_picked = float('inf') while cubes: if cubes[0] >= cubes[-1]: pick = cubes.pop(0) else: pick = cubes.pop() if pick > last_picked: return "No" last_picked = pick return "Yes" if __name__ == '__main__': t = int(input().strip()) results = [] for _ in range(t): n = int(input().strip()) cubes = list(map(int, input().strip().split())) results.append(can_stack_cubes(cubes)) for result in results: print(result)
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 →