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.


HackerRank Piling Up! solution in python


Problem solution in Python 2 programming.

# 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 -= 1


Problem solution in Python 3 programming.

# 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')