Minimum Loss 1

  • + 0 comments
    import bisect
    
    def minimumLoss(price):
        min_price = float('inf')
        sorted_price = []
        for num in price:
            idx = bisect.bisect_right(sorted_price, num)
            if idx < len(sorted_price):
                min_price = min(min_price, sorted_price[idx] - num)
            sorted_price.insert(idx, num)
            
        return min_price