Kotlin | one-liner
\n#### Join me on Telegram\nhttps://t.me/leetcode_daily_unstoppable/250\n#### Problem TLDR\nMax running sum\n#### Intuition\nJust sum all the values and compute
![image.png](https://assets.leetcode.com/users/images/257d1f08-62ae-49cf-84d5-304d497c79dd_1687146109.8661134.png)\n#### Join me on Telegram\nhttps://t.me/leetcode_daily_unstoppable/250\n#### Problem TLDR\nMax running sum\n#### Intuition\nJust sum all the values and compute the `max`\n\n#### Approach\nLet\'s write Kotlin `fold` one-liner\n#### Complexity\n- Time complexity:\n$$O(n)$$\n- Space complexity:\n$$O(1)$$\n#### Code\n```\n\n    fun largestAltitude(gain: IntArray): Int = gain\n        .fold(0 to 0) { (max, sum), t -> maxOf(max, sum + t) to (sum + t) }\n        .first\n\n```
['Kotlin']