Sort by

recency

|

979 Discussions

|

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

    Saw lots of deque, but I think a direct index approach is faster no? Avoids updating the list.

    for i in range(int(input())):
        n = int(input())
        a = 0
        b = n-1
        l = list(map(int,input().split()))
        t = max(l[a],l[b])
        
        while a != b: 
            if l[a] >= l[b]:
                if l[a]<= t:
                    outcome = 'Yes'
                    a += 1
                else:
                    outcome = 'No'
                    break
            else:
                if l[b]<= t:
                    outcome = 'Yes'
                    b -= 1
                else:
                    outcome = 'No'
                    break
                
        print(outcome)
    
  • + 0 comments
    T = int(input())
    blocks = []
    
    for i in range(T):
        n = int(input())
        block = list(map(int,input().split()))
        start = 0
        end = n-1
        stack = []
        
            
        for i in range(n):
                left = block[start]
                right = block[end]
                
                if i == 0:
                    if left >= right:
                        stack.append(left)
                        start +=1
                    else:
                        stack.append(right)
                        end -=1
                else:
                    if left <= stack[-1] and left >= right:
                        stack.append(left)
                        start +=1
                    elif right <= stack[-1] and right > left:
                        stack.append(right)
                        end -=1
                    else:
                        print('No')
                        break
                
        
        if (len(stack) == n):
            print('Yes')