Sort by

recency

|

960 Discussions

|

  • + 0 comments
    1. Sort cubes list as an expected stack to be find
    2. Check if picking only left or right cubes is possible to pile the expected stack
    T = int(input())
    
    def is_stackable(cubes):
        expected_stack = sorted(cubes)
        
        left, right = 0, len(cubes) - 1
        while len(expected_stack) > 0:
            expected_block = expected_stack.pop()
            
            if cubes[left] == expected_block:
                left += 1
            elif cubes[right] == expected_block:
                right -= 1
            else:
                return False
            
        return True
    
    for t in range(T):
        n = int(input())
        cubes = list(map(int, input().split()))
        print("Yes" if is_stackable(cubes) else "No")
    
  • + 1 comment

    '''if the largest block isn't in the first or last position to begin with, the blocks are not stackable'''

    for _ in range(int(input())): n = int(input()) blocks = list(map(int, input().split())) if blocks[0] == max(blocks) or blocks[-1] == max(blocks): print("Yes") else: print("No")

  • + 0 comments

    This is a solution without any dependencies

    for i in range(int(input())):
        l=int(input())
        left,right=0,-1
        ls=list(map(int,input().split()))
        prev=0
        for k in range(l):
            ind=0
            if ls[left]>ls[right]:
                ind=left
            elif ls[right]>ls[left]:
                ind=right
            else:
                ind=left
            if(ls[ind]<=prev) or (prev==0):
                prev=ls[ind]
                ls.pop(ind)     
        if ls==[]:
            print("Yes")
        else:
            print("No")
    
  • + 0 comments
    1. n = int(input())
    2. for i in range(n):
    3. len_blocks = input()
    4. block = list(map(int,input().split()))
    5. li = []
    6. l,r = 0 , len(block)-1
    7. while(l<=r):
    8. if(block[r]>=block[l]):
    9. li.append(block[r])
    10. r -=1
    11. else:
    12. li.append(block[l])
    13. l+=1
    14. if((li == sorted(li, reverse=True)) == True):
    15. print("Yes")
    16. else:
    17. print("No") '''
  • + 0 comments

    t = int(input()) for _ in range(t): n = int(input()) ls = list(map(int, input().split())) k = float('inf')

    left, right = 0, n - 1
    while left <= right:
        if k < max(ls[left], ls[right]):
            print("No")
            break
        if ls[left] > ls[right]:
            k = ls[left]
            left += 1
        else:
            k = ls[right]
            right -= 1
    else:
        print("Yes")