Javascript solution, if anyone is interested
var maxProfit = function(prices) {\n        var min = Number.MAX_SAFE_INTEGER; \n        var max = 0;\n        for (var i = 0; i < prices.length; i++) {\n      
    var maxProfit = function(prices) {\n        var min = Number.MAX_SAFE_INTEGER; \n        var max = 0;\n        for (var i = 0; i < prices.length; i++) {\n            min = Math.min(min, prices[i]);\n            max = Math.max(max, prices[i] - min);\n        }\n        return max;\n    };
['JavaScript']