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 STDOUTdefcan_stack_cubes(test_cases):results=[]forcaseintest_cases:n,blocks=caseleft,right=0,n-1current_top=float('inf')can_stack=Truewhileleft<=right:ifblocks[left]>=blocks[right]:chosen_block=blocks[left]left+=1else:chosen_block=blocks[right]right-=1ifchosen_block>current_top:can_stack=Falsebreakcurrent_top=chosen_blockresults.append("Yes"ifcan_stackelse"No")returnresults# Read inputdefmain():importsysinput=sys.stdin.readdata=input().strip().split("\n")T=int(data[0])test_cases=[]foriinrange(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)forresultinresults: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 →