Skip to content
Programming101
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

Learn everything about programming

HackerRank Piling Up! problem solution in python

YASH PAL, 31 July 2024

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

coding problems solutions Python Solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes