Solutions for stock prices of a company

    • @JavierVow
    • @jacob, submitted in Python 2, achived 100% score
    import sys
    import json
    
    def solve(prices):
        if not prices or len(prices) < 2:
            return
    
        min_price = prices[0]
        max_diff = -sys.maxsize
        for price in prices[1:]:
            if price - min_price > max_diff:
                max_diff = price - min_price
            if price < min_price:
                min_price = price
    
        return max_diff
    • @JavierVow
    • @jacob, submitted in Python 3, achived 100% score
    import sys
    import json
    
    def solve(prices):
        if not prices or len(prices) < 2:
            return
    
        min_price = prices[0]
        max_diff = -sys.maxsize
        for price in prices[1:]:
            if price - min_price > max_diff:
                max_diff = price - min_price
            if price < min_price:
                min_price = price
    
        return max_diff