Kotlin | min-max
Join me on Telegram\nhttps://t.me/leetcode_daily_unstoppable/129\n#### Intuition\nMax profit will be the difference between max and min. One thing to note, the 
#### Join me on Telegram\nhttps://t.me/leetcode_daily_unstoppable/129\n#### Intuition\nMax profit will be the difference between `max` and `min`. One thing to note, the `max` must follow after the `min`.\n\n#### Approach\n* we can just use current value as a `max` candidate instead of managing the `max` variable.\n#### Complexity\n- Time complexity:\n$$O(n)$$\n- Space complexity:\n$$O(1)$$\n#### Code\n```\nclass Solution {\n    fun maxProfit(prices: IntArray): Int {\n        var min = prices[0]\n        var profit = 0\n        prices.forEach { \n            if (it < min) min = it\n            profit = maxOf(profit, it - min)\n        }\n        return profit\n    }\n}\n```
['Dynamic Programming', 'Kotlin']