Sort by

recency

|

947 Discussions

|

  • + 0 comments

    The description of problem statement seems a bit odd to me.

    Here's a better explanation of the problem statement for future porblems solvers.

    Piling Up! Problem

    What Are We Trying to Do?

    Your task is to decide if it is possible to build a single tower of blocks from a given row of blocks. The tower (stack) must follow these rules:

    1. Blocks in the stack must be in non-increasing order (each block on top must be smaller than or equal to the one below it).
    2. You must use all the blocks in the row to complete the stack.

    What Is the Situation?

    • You are given a row of blocks, each with a size written on it (a number).
    • At each step, you are allowed to pick a block from either the left end or the right end of the row. Once a block is picked, it is added to your stack (tower) and removed from the row.
    • You can smartly (freely) choose which end to pick from at every step.

    Rules You Must Follow:

    1. You can only pick blocks from the two ends (leftmost or rightmost block) of the row.
    2. Blocks must be added to the stack in non-increasing order:
      • A block can only be added if its size is less than or equal to the block already on top of the stack.
    3. You must use all the blocks in the row to complete the stack.

    What You Have to Decide:

    For each test case:

    • If you can create a valid stack by following the rules, print "Yes".
    • If it is impossible to create a valid stack, print "No".
  • + 0 comments
    from collections import deque
    
    num_test = int(input())
    
    for _ in range(num_test):
        
        num_block = int(input())
        blocks = deque(map(int, input().split()))
        pile = []
        
        while blocks:
            
            if blocks[0] <= blocks[-1]:
                pile.append(blocks.pop())
            
            else:
                pile.append(blocks.popleft())
                
        if pile == sorted(pile, reverse=True):
            print('Yes')
        
        else:
            print('No')
    
  • + 0 comments

    I know the expectation is to use deque to solve this. But still went ahead with a simpler approach.

    test_cases = int(input()) for i in range(test_cases): ln = int(input()) blocks = list(map(int, input().split())) if max(blocks) == blocks[0] or max(blocks) == blocks[-1]: print("Yes") else: print("No")

  • + 0 comments

    t=int(input())

    while t:

    size=int(input())
    
    li=list(map(int, input().split()))
    
    mini=min(li)
    
    minindex=li.index(mini)
    
    modfirst=sorted(li[:minindex+1], reverse=True)
    
    modsecond=sorted(li[minindex:])
    
    if li[:minindex+1]==modfirst and li[minindex:]==modsecond:
        print("Yes")
    else:
        print("No")
    t-=1
    
  • + 0 comments
    for t in range(int(input())):
        n = int(input())
        lst = list(map(int, input().split()))
        result = 'Yes'
        previous_item = None
        while lst:
            if lst[0] >= lst[-1]:
                current_item = lst.pop(0)
            else:
                current_item = lst.pop(-1)
            if previous_item:
                if current_item > previous_item:
                    result = 'No'
                    break
            previous_item = current_item
        print(result)