• + 1 comment

    Solution using deques, the splicing solutions on here are interesting but unfriendly to read

    from collections import deque
    
    for _ in range(int(input())):
        size = int(input())
        blocks = deque(map(int,input().split()))
        head = float('inf')
        win = True
        
        while(len(blocks) > 1 and win):
            
            left, right = blocks[0], blocks[-1]
            if left <= head and right <= head:
                
                if left >= right:
                    head = blocks.popleft()
                else: head = blocks.pop()
            
            else: win = False
        
        print("Yes") if win and blocks[0] <= head else print("No")