Solutions for Left and Right

    • @kristeencoupp91
    • @Ethan, submitted in Python 3, achived 100% score
    def solve(arr):
        arr.sort()
        n = len(arr) 
        leftmax=arr[0]
        rightmin=arr[n-1]
        fl=[]
        for i in range(n-1,1,-1):
            if arr[i]<rightmin:
                rightmin=arr[i]
            fl.append(rightmin)
        fl[0:]=fl[::-1]
        for i in range(1,n-1):
            if arr[i]> leftmax:
                leftmax=arr[i]
            if leftmax<=arr[i] and arr[i]<=fl[i-1]:
                return arr[i]
        return -1