Sort by

recency

|

985 Discussions

|

  • + 0 comments
    t = int(input())
    for _ in range(t):
        n = int(input())
        blocks = list(map(int, input().split()))
        left, right = 0, n - 1
        last = float('inf')   # start with "infinity" (no restriction yet)
        ok = True
        
        while left <= right:
            # choose the bigger cube from either end
            if blocks[left] >= blocks[right]:
                curr = blocks[left]
                left += 1
            else:
                curr = blocks[right]
                right -= 1
            
            # check if it's valid
            if curr > last:
                ok = False
                break
            last = curr
        
        print("Yes" if ok else "No")
    
  • + 0 comments

    T = int(input()) for j in range(T): n = int(input()) blocks = list(map(int, input().split())) result = True left, right = 0, n-1 top = float('inf') while left <= right: if blocks[left] <= top and (blocks[left] >= blocks[right]): top = blocks[left] left += 1 elif blocks[right] <= top: top = blocks[right] right -= 1 else: result = False break

    print("Yes" if result else "No")
    
  • + 1 comment

    Here, it's my code!

    for _ in range(int(input())):
        n = int(input())
    l = list(map(int,input().split()))
    result = "Yes"
    for i in range(1,n-1):
        if(l[i] > l[i-1] and l[i] > l[i+1]):
            result = "No"
            break
    print(result)
    
  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from collections import deque
    if __name__ == '__main__':
        T = int(input())
        for _ in range(T):
            n = int(input())
            cube = deque(map(int,input().split()))
            ans = True
            last = max(cube)
            
            while cube:
                if cube[0] >= cube[-1]:
                    current = cube.popleft()
                else:
                    current = cube.pop()
                    
                if last is None or current <= last:
                    last = current
                else:
                    ans = False
                    break
            print("Yes" if ans else "No")
    
  • + 0 comments

    The description of this is terrible. This is what it's trying to ask of you.

    You’re given a row of cubes, each with a length. You can only pick cubes from either end — leftmost or rightmost — one at a time. Your goal is to stack them vertically, so that each cube you place is not longer than the one below it. In other words: - You’re building a pile from bottom to top. - Each new cube must be equal to or smaller than the one you just placed. - You can only pick from the ends of the row — no grabbing from the middle.