HackerRank Piling Up! problem solution in Python YASH PAL, 31 July 202417 January 2026 HackerRank Piling Up! problem solution in Python – In this Piling Up! problem, we need to develop a Python program that can read a single integer containing the number of test cases. And then we need to print yes or no on the output screen.There is a horizontal row of n cubes. The length of each cube is given. You need to create a new vertical pile of cubes. The new pile should follow these directions: if cub[i] is on top of cub[j], then sideLength[j] >= sideLength[i]. When stacking the cubes, you can only pick up either the leftmost or the rightmost cube each time. Print Yes if it is possible to stack the cubes. Otherwise, print No.HackerRank Piling Up! problem solution in Python 2.# Enter your code here. Read input from STDIN. Print output to STDOUT tests = int(raw_input().strip()) while tests > 0: n = int(raw_input().strip()) arr = map(int, raw_input().strip().split(' ')) Lmin = arr[:] Rmin = arr[:] for i in range(1,n): Lmin[i] = min(Lmin[i-1], arr[i]) for i in range(n-2, -1, -1): Rmin[i] = min(Rmin[i+1], arr[i]) result = 'Yes' for i in range(1,n-1): if Lmin[i] < arr[i] and Rmin[i] < arr[i]: result = 'No' break print result tests -= 1Piling Up! Problem solution in Python 3.# Enter your code here. Read input from STDIN. Print output to STDOUT for t in range(int(input())): input() lst = [int(i) for i in input().split()] min_list = lst.index(min(lst)) left = lst[:min_list] right = lst[min_list+1:] if left == sorted(left,reverse=True) and right == sorted(right): print("Yes") else: print("No") Problem solution in pypy programming.# Enter your code here. Read input from STDIN. Print output to STDOUT from collections import deque n = int(raw_input()) for _ in range(n): m = int(raw_input()) cubes = deque(map(int, raw_input().strip().split())) cube = '' for _ in range(m): left, right = cubes[0], cubes[-1] if left >= right: if cube >= left or cube == '': cube = left cubes.popleft() else: if cube >= right or cube == '': cube = right cubes.pop() if len(cubes) == 0: print 'Yes' else: print 'No' Problem solution in pypy3 programming.# https://www.hackerrank.com/challenges/piling-up if __name__ == '__main__': for i in range(int(input())): num = int(input()) last_num = 99999999999 arr = map(int, input().split()) items = list(arr) start = 0 end = len(items) - 1 while start <= end: if items[start] > items[end]: if items[start] <= last_num: last_num = items[start] # print(items[start], last_num - items[start]) start += 1 else: print('No') break else: if items[end] <= last_num: last_num = items[end] # print(items[end], last_num - items[end]) end -= 1 else: # print(last_num - items[end]) print('No') break if start > end: print('Yes') # else: print('NO') coding problems solutions Hackerrank Problems Solutions Python Solutions HackerRankPython