18.06.2023
1732. Find the Highest Altitude easy
blog post
Join me on Telegram
https://t.me/leetcode_daily_unstoppable/250
Problem TLDR
Max running sum
Intuition
Just sum all the values and compute the max
Approach
Let’s write Kotlin fold
one-liner
Complexity
Time complexity:
O(n)Space complexity:
O(1)
Code
fun largestAltitude(gain: IntArray): Int = gain
.fold(0 to 0) { (max, sum), t -> maxOf(max, sum + t) to (sum + t) }
.first