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
def can_stack_cubes(test_cases):
results = []
for case in test_cases:
n, blocks = case
left, right = 0, n - 1
current_top = float('inf')
can_stack = True
while left <= right:
if blocks[left] >= blocks[right]:
chosen_block = blocks[left]
left += 1
else:
chosen_block = blocks[right]
right -= 1
if chosen_block > current_top:
can_stack = False
break
current_top = chosen_block
results.append("Yes" if can_stack else "No")
return results
Read input
def main():
import sys
input = sys.stdin.read
data = input().strip().split("\n")
T = int(data[0])
test_cases = []
for i in range(1, 2 * T, 2):
n = int(data[i])
blocks = list(map(int, data[i + 1].split()))
test_cases.append((n, blocks))
results = can_stack_cubes(test_cases)
for result in results:
print(result)
if name == "main":
main()
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
def can_stack_cubes(test_cases): results = [] for case in test_cases: n, blocks = case left, right = 0, n - 1 current_top = float('inf') can_stack = True
Read input
def main(): import sys input = sys.stdin.read data = input().strip().split("\n")
if name == "main": main()