Piling Up Hacker Rank Solution – Queslers

Problem: Piling Up Hacker Rank Solution

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 cubei is on top of cubej then sideLengthj >= sideLengthi.
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”. Do not print the quotation marks.

Input Format :

The first line contains a single integer T, the number of test cases.
For each test case, there are 2 lines.
The first line of each test case contains n, the number of cubes.
The second line contains n space separated integers, denoting the sideLengths of each cube in that order.

Constraints :

  • 1 <= T <= 5
  • 1 <= n <= 10^5
  • 1 <= sideLength <= 2^31

Output Format :

For each test case, output a single line containing either “Yes” or “No” without the quotes.

Sample Input :

4 3 2 1 3 4
1 3 2

Sample Output :


Explanation :

In the first test case, pick in this order: left -4 , right -4 , left -3 , right – 3, left – 2, right – 1. In the second test case, no order gives an appropriate arrangement of vertical cubes. 3 will always come after either 1 or 2.

Piling Up Hacker Rank 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'
  print result
  tests -= 1

Piling Up Hacker Rank Solution in python 3

# Enter your code here. Read input from STDIN. Print output to STDOUT
for t in range(int(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):

Piling Up Hacker Rank Solution in pypy

# 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
            if cube >= right or cube == '':
                cube = right
    if len(cubes) == 0:
        print 'Yes'
        print 'No'

Piling Up Hacker Rank Solution in pypy 3

# 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
                if items[end] <= last_num:
                    last_num = items[end]
                    # print(items[end], last_num - items[end])
                    end -= 1
                    # print(last_num - items[end])
        if start > end:
        # else: print('NO')
Piling Up Hacker Rank Solution Review:

In our experience, we suggest you solve this Piling Up Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Piling Up is available on Hacker Rank for Free, if you are stuck anywhere between compilation, just visit Queslers to get all Hacker Rank Solution


I hope this Piling Up Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Hacker Rank Problem & Solutions >>

itertools.product() Hacker Rank Solution

String Validators Hacker Rank Solution

Text Alignment Hacker Rank solution

String validators Hacker Rank Solution

Staircase Hacker Rank Solution

Leave a Reply

Your email address will not be published.