• + 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")