Sort by

recency

|

981 Discussions

|

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

    Enter your code here. Read input from STDIN. Print output to STDOUT

    from collections import deque

    num_of_tests = int(input())

    for ntest in range(num_of_tests): # read number of blocks num_of_blocks = int(input())

    # read block sizes
    blocks = deque(map(int,input().strip().split()))
    
    # put down largest block from left/right
    if blocks[0] >= blocks[-1]:
        base_block = blocks[0]
        blocks.popleft()
    else:
        base_block = blocks[-1]
        blocks.pop()
    
    # See if the rest can be stacked 
    result = "Yes"   
    while blocks:
        left_block = blocks[0]
        right_block = blocks[-1]
        if left_block >= right_block:
            current_block = left_block
            blocks.popleft()
        else:
            current_block = right_block
            blocks.pop()
    
        if current_block <= base_block:
            base_block = current_block
        else:
            result = "No"
            break
    
    print(result)
    
  • + 0 comments

    here is my solution and works

    T =int(input())
    pile=[]
    bandera=True
    
    for i in range (T):
        n=int(input())
        bloques=list(map(int, input().split()))
        pile.append([n,bloques])
        
    for repeticiones, bloques in pile:
        while len(bloques)>=2:
            top=max(bloques[0], bloques[-1])
            bloques.remove(top)    
            if(top >= bloques[-1]):
                bloques.pop()
                bandera=True
            else:
                bandera= False
                break
        print("Yes" if bandera else "No")
    
  • + 0 comments
    import math
    
    def main():
        t = int(input())
        for _ in range(t):
            _, blocks = int(input()), list(map(int, input().split()))
            result = True
            top = math.inf
            i, j = 0, len(blocks) - 1
    
            while i <= j and result:
                left = blocks[i]
                right = blocks[j]
                if left >= right:
                    if left <= top:
                        top=left
                        i+=1
                    else:
                        result = False
                else:
                    if right <= top:
                        top=right
                        j-=1
                    else:
                        result = False
    
            if result:
                print("Yes")
            else:
                print("No")
    
    if __name__ == "__main__":
        main()