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