Sort by

recency

|

984 Discussions

|

  • + 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.

  • + 0 comments
    def cubos_decreciente(arr):
        izquierda = 0
        derecha = len(arr) - 1
        maximo = max(arr[izquierda], arr[derecha])
    
        while izquierda <= derecha:
            if arr[izquierda] >= arr[derecha]:
                if arr[izquierda] <= maximo:
                    maximo = arr[izquierda]
                    izquierda += 1
                else:
                    return False
    
            else:
                if arr[derecha] <= maximo:
                    maximo = arr[derecha]
                    derecha -= 1
                else:
                    return False
                
        return True
    
    
    n_ejercicios = int(input().strip())
    
    for _ in range(n_ejercicios):
      len_arr = int(input().strip())
      arr = list( map(int, input().split()))
      print("Yes" if cubos_decreciente(arr) else "No")