Sort by

recency

|

973 Discussions

|

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from collections import deque
    for _ in range(int(input())):
        n = int(input())
        blocks = deque(map(int,input().split())) 
        top_cube = 0
        while blocks:
            left_most = blocks[0]
            right_most = blocks[-1]
            left_greater = left_most > right_most
            next_cube = left_most if left_greater else right_most
            if not top_cube or next_cube <= top_cube:
                top_cube = blocks.popleft() if left_greater else blocks.pop()
            else:
                top_cube = 0
                break
        
        print ("Yes" if top_cube else "No")
    
  • + 0 comments

    Here is HackerRank Piling Up! in python solution - https://programmingoneonone.com/hackerrank-piling-up-problem-solution-in-python.html

  • + 0 comments
    from collections import deque
    
    T = int(input())
    
    for _ in range(T):
        n = int(input())
        cubes = deque(map(int, input().split()))
    
        last = float('inf')
        possible = True
    
        while cubes:
            
            if cubes[0] >= cubes[-1] and cubes[0] <= last:
                last = cubes.popleft()
            elif cubes[-1] >= cubes[0] and cubes[-1] <= last:
                last = cubes.pop()
            else:
                possible = False
                break
    
        print("Yes" if possible else "No")
    
  • + 0 comments

    from collections import deque

    def is_stackable(cubes): dq = deque(cubes) last = float('inf')

    while dq:
        if dq[0] > dq[-1]:
            next = dq.popleft()
        else:
            next = dq.pop()
    
        if next > last:
            return "No"
        last = next
    
    return "Yes"
    

    t_cases = int(input())

    for _ in range(t_cases): n = int(input()) cubes = list(map(int, input().split())) print(is_stackable(cubes))

  • + 0 comments
    def arrange(l):
        n = len(l)
        l1 = l[:]
        ls = []
        for i in range(n):
            if(l[len(l)-1] > l[0]):
                ls.append(l[len(l)-1])
                l.pop(len(l)-1)
            else:
                ls.append(l[0])
                l.pop(0)
        if (sorted(l1, reverse=True) == ls):
            return "YES"
        else:
            return "NO"
    
    
    if __name__ == '__main__':
        t = int(input())
        for i in range(t):
            n = int(input())
            ls = list(map(int, input().split()))
            print(arrange(ls))