Sort by

recency

|

972 Discussions

|

  • + 0 comments

    Here is HackerRank Piling Up! in python solution - https://programmingoneonone.com/hackerrank-piling-up-problem-solution-in-python.html

  • + 0 comments
    from collections import deque
    
    T = int(input())
    
    for _ in range(T):
        n = int(input())
        cubes = deque(map(int, input().split()))
    
        last = float('inf')
        possible = True
    
        while cubes:
            
            if cubes[0] >= cubes[-1] and cubes[0] <= last:
                last = cubes.popleft()
            elif cubes[-1] >= cubes[0] and cubes[-1] <= last:
                last = cubes.pop()
            else:
                possible = False
                break
    
        print("Yes" if possible else "No")
    
  • + 0 comments

    from collections import deque

    def is_stackable(cubes): dq = deque(cubes) last = float('inf')

    while dq:
        if dq[0] > dq[-1]:
            next = dq.popleft()
        else:
            next = dq.pop()
    
        if next > last:
            return "No"
        last = next
    
    return "Yes"
    

    t_cases = int(input())

    for _ in range(t_cases): n = int(input()) cubes = list(map(int, input().split())) print(is_stackable(cubes))

  • + 0 comments
    def arrange(l):
        n = len(l)
        l1 = l[:]
        ls = []
        for i in range(n):
            if(l[len(l)-1] > l[0]):
                ls.append(l[len(l)-1])
                l.pop(len(l)-1)
            else:
                ls.append(l[0])
                l.pop(0)
        if (sorted(l1, reverse=True) == ls):
            return "YES"
        else:
            return "NO"
    
    
    if __name__ == '__main__':
        t = int(input())
        for i in range(t):
            n = int(input())
            ls = list(map(int, input().split()))
            print(arrange(ls))
    
  • + 0 comments

    My Soln:

    from math import ceil T = int(input()) my_list = [] for _ in range(T*2): my_list.append(list(map(int, input().split())))

    new_list = []

    for i in range(1,len(my_list),2): new_list.append(my_list[i])

    for j in range(0,len(new_list)): for k in range(0,ceil(len(new_list[j])/3)): if ( (new_list[j][k + 1] <= new_list[j][len(new_list[j]) - (k + 1)] and new_list[j][len(new_list[j]) - (k + 2)] <= new_list[j][len(new_list[j]) - (k + 1)]) or (new_list[j][k + 1] <= new_list[j][k] and new_list[j][len(new_list[j]) - (k + 2)] <= new_list[j][k])): passed_all = True

        else:
            print("No")
            passed_all = False
            break
    
    if passed_all == True:
        print("Yes")