Sort by

recency

|

987 Discussions

|

  • + 0 comments

    N = int(input())

    for _ in range(N):

    nos = int(input())
    in_list = input().split()
    start = int(in_list[0])
    end = int(in_list[-1])
    if start<end:
        val = end
        in_list.pop(-1)
    else:
        val = start
        in_list.pop(0)
    
    while len(in_list)>0:
        start = int(in_list[0])
        end = int(in_list[-1])
        if val>=end and end>=start:
            val = end
            in_list.pop(-1)
        elif val>=start and start>=end:
            val = start
            in_list.pop(0)
        else:
            print("No")
            break
    
    if len(in_list)==0:
        print("Yes")
    
  • + 0 comments
    for _ in range(int(input())):
        n = int(input())
        s = list(map(int,input().split()))
        pair=[]
        midval=-1
        for i in range(len(s)//2):
            pair.append((s[i],s[-(i+1)]))
        flag="Yes"
        global_current=pair
        for i in range(1,len(pair)):
            prev=pair[i-1]
            curr=pair[i]
            if (curr[0]>prev[0] and  curr[0]>prev[1]) or (curr[1]>prev[0] and  curr[1]>prev[1]):
                flag="No"
                global_current=curr
        if len(s)%2==1 and flag=="Yes":
            midval=s[len(s)//2]
            if midval>global_current[0][0] and midval>global_current[0][1]:
                flag="No"
        print(flag)
    
  • + 0 comments
    t = int(input())
    for _ in range(t):
        n = int(input())
        blocks = list(map(int, input().split()))
        left, right = 0, n - 1
        last = float('inf')   # start with "infinity" (no restriction yet)
        ok = True
        
        while left <= right:
            # choose the bigger cube from either end
            if blocks[left] >= blocks[right]:
                curr = blocks[left]
                left += 1
            else:
                curr = blocks[right]
                right -= 1
            
            # check if it's valid
            if curr > last:
                ok = False
                break
            last = curr
        
        print("Yes" if ok else "No")
    
  • + 0 comments

    T = int(input()) for j in range(T): n = int(input()) blocks = list(map(int, input().split())) result = True left, right = 0, n-1 top = float('inf') while left <= right: if blocks[left] <= top and (blocks[left] >= blocks[right]): top = blocks[left] left += 1 elif blocks[right] <= top: top = blocks[right] right -= 1 else: result = False break

    print("Yes" if result else "No")
    
  • + 1 comment

    Here, it's my code!

    for _ in range(int(input())):
        n = int(input())
    l = list(map(int,input().split()))
    result = "Yes"
    for i in range(1,n-1):
        if(l[i] > l[i-1] and l[i] > l[i+1]):
            result = "No"
            break
    print(result)