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

Output Format
For each test case, output a single line containing either "Yes" or "No" without the quotes.

hackerrank piling up problem solution in python

Problem solution in python 2 programming language.

from collections import deque 
import sys
for _ in range(raw_input()):
    n = input()
    arr = map(int,raw_input().split())
    for i in arr:
        assert i<=2**31 - 1
    lst = deque(arr)

    curr = 9999999999999999
    flag = 0
    if (len(lst)<=2):
        print "Yes"
    left = lst.popleft()
    right = lst.pop()
    latest = -1
    while (len(lst)>0):
        flag = 0
        if (left >= right and left <= curr):
            curr = left
            left = lst.popleft()
            latest = left
            flag = 1
        elif (right> left and right <= curr):
            curr = right
            right = lst.pop()
            latest = right
            flag = 1
        if flag == 0:
    if len(lst)>0 or latest > curr:
        print "No"
        print "Yes"

Problem solution in python 3 programming language.

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=Trueand right == sorted(right):