Javascript - O (n)
\n/**\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(prices) {\n    let min = prices[0], max = 0;\n    \n    for(let i = 1; i 
```\n/**\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(prices) {\n    let min = prices[0], max = 0;\n    \n    for(let i = 1; i < prices.length; i++){\n        if(prices[i] - min > max){\n            max = prices[i] - min;\n        }\n        \n        if(prices[i] < min) min = prices[i]\n    }\n    \n    return max;\n};\n```
['JavaScript']