Hackerrank: Pilling Up! challenge
That was a fun little challenge to code against, although my solution was very different from yours!

With those kinds of challenges, it can be tempting to just write throw-away code. I would suggest though, if you are serious about coding, to just try to write the most professional code you can, even if it's just to solve this one challenge. 



In particular, I find your code is not very expressive. There's no functions/methods/classes, there's really not anything telling me (or future you) what this code is for at all, so I'm having to actually read the code from beginning to end to even get an idea what it's supposed to do (let alone if it's doing it correctly). This also makes it much less reusable. 



We can start by organizing input handling separately from program logic. In fact, I think __main__ would be a perfect place to handle getting input. You'll notice my code is somewhat more verbose, I personally prefer to make it obvious when doing "breaky" things like reading raw text input.

if __name__ == "__main__":
    num_cases = int(input())
    for case in range(num_cases):
        no_of_cubes = int(input())
        side_lengths = list(map(int, input().strip().split()))


I don't think it would be unreasonable to create a function to handle text input, but that may be a bit much for this. So, we have our input, now we just need to handle it.



One data structure to consider, and for which it seems like this challenge was written, is the deque...


  Deques are a generalization of stacks and queues (the name is pronounced “deck” and is short for “double-ended queue”). Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.


However, you found a shorter, less literal way to pass the test cases, which, in the end, is the goal. So if you wanted to keep it at that, I'd just move the logic into a function and return a bool, and call it a day. 

def can_be_piled(no_of_cubes: int, side_lengths: List) -&gt; bool:
    if max(side_lengths) not in (side_lengths[0], side_lengths[-1]):
        return False
    return True


I also made a few other utility functions, one to split up the side lengths, the other to display the output. Note that I used Python 3 type hints in each function signature, in case that looks unfamiliar.

from typing import List

def can_be_piled(no_of_cubes: int, side_lengths: List) -&gt; bool:
    if max(side_lengths) not in (side_lengths[0], side_lengths[-1]):
        return False
    return True

def get_side_lengths(raw_input: str) -&gt; List:
    return list(map(int, raw_input.strip().split()))

def display_output(truthy: bool) -&gt; None:
    if truthy:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    num_cases = int(input())
    for case in range(num_cases):
        no_of_cubes = int(input())
        side_lengths = get_side_lengths(input())
        display_output(can_be_piled(no_of_cubes, side_lengths))