• + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    def can_stack_cubes(test_cases):
        results = []
        for case in test_cases:
            n, blocks = case
            left, right = 0, n - 1
            current_top = float('inf')
            can_stack = True
    
            while left <= right:
                if blocks[left] >= blocks[right]:
                    chosen_block = blocks[left]
                    left += 1
                else:
                    chosen_block = blocks[right]
                    right -= 1
    
                if chosen_block > current_top:
                    can_stack = False
                    break
    
                current_top = chosen_block
    
            results.append("Yes" if can_stack else "No")
    
        return results
    
    # Read input
    def main():
        import sys
        input = sys.stdin.read
        data = input().strip().split("\n")
    
        T = int(data[0])
        test_cases = []
    
        for i in range(1, 2 * T, 2):
            n = int(data[i])
            blocks = list(map(int, data[i + 1].split()))
            test_cases.append((n, blocks))
    
        results = can_stack_cubes(test_cases)
    
        for result in results:
            print(result)
    
    if __name__ == "__main__":
        main()