Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
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.
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.
For each test case, output a single line containing either “Yes” or “No” without the quotes.
2
6
4 3 2 1 3 4
3
1 3 2
Yes
No
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.
# 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
# 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")
# 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'
# 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')
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