• + 0 comments

    Enter your code here. Read input from STDIN. Print output to STDOUT

    from collections import deque

    num_of_tests = int(input())

    for ntest in range(num_of_tests): # read number of blocks num_of_blocks = int(input())

    # read block sizes
    blocks = deque(map(int,input().strip().split()))
    
    # put down largest block from left/right
    if blocks[0] >= blocks[-1]:
        base_block = blocks[0]
        blocks.popleft()
    else:
        base_block = blocks[-1]
        blocks.pop()
    
    # See if the rest can be stacked 
    result = "Yes"   
    while blocks:
        left_block = blocks[0]
        right_block = blocks[-1]
        if left_block >= right_block:
            current_block = left_block
            blocks.popleft()
        else:
            current_block = right_block
            blocks.pop()
    
        if current_block <= base_block:
            base_block = current_block
        else:
            result = "No"
            break
    
    print(result)