Piling Up! HackerRank solution

def checkposiblilty(side_length):

    left_count = 0
    right_count = len(side_length)-1
    base_value = float("inf")
    while left_count <= right_count:
        left_value = side_length[left_count]

        right_value = side_length[right_count]

        if left_value >= right_value and left_value <= base_value:
            base_value = left_value
            left_count += 1

        elif right_value > left_value and right_value <= base_value:
            base_value = right_value
            right_count -= 1

        else:
            return ('No')

    return ('Yes')


test_case = int(input())
for i in range(test_case):
    block_size = int(input())
    side_length = [int(length) for length in input().split()]
    print(checkposiblilty(side_length))

Comments

Popular posts from this blog

Mean, Var, and Std in numpy HackerRank

Min and Max in numpy HackerRank

Collections.deque() HackersRank Solution