Sort by

recency

|

955 Discussions

|

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

  • + 0 comments
    from collections import deque
    
    def try_next(d):
        current = max(d[0], d[-1])
    
        for _ in range(round(len(d)+1/2)):        
            if len(d) == 0:
                return True
    
            left = d[0]
            right = d[-1]
    
            if left <= current or right <= current:
                if left >= right and left <= current:
                    current = d.popleft()
                    if len(d) == 0:
                        return True
                    left = d[0]
                
                if right <= current and right >= left:
                    current = d.pop()
            else:
                return False
    
        if len(d) == 0:
            return True
    
    
    if __name__ == '__main__':
        for _ in range(int(input())):
            size = int(input())
            l = list(map(int, input().split()))
            d = deque(l)
            print("Yes" if try_next(d) else "No")
    
  • + 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()
    
  • + 0 comments
    for i in range(int(input())):
        n = int(input())
        p = list(map(int, input().split()))
        a = "Yes"
        for j in range(n//2):
            if max(p[j], p[~j]) < max(p[j+1], p[~(j+1)]):
                a = "No"
                break
        print(a)
    
  • + 0 comments
    from collections import deque
    
    for _ in range(int(input())):
        _ = input()
        d = deque(list(map(int, input().split())))
        lst = []
        if d[0] <= d[-1]:
            lst.append(d.pop())
        else:
            lst.append(d.popleft())
        while len(d) > 0:
            if d[0] <= d[-1] and d[-1] <= lst[-1]:
                lst.append(d.pop())
                continue
            elif d[0] > d[-1] and d[0] <= lst[-1]:
                lst.append(d.popleft())
                continue
            else:
                break
    
        print("Yes" if len(d) == 0 else "No")