LeetCode Entry

1732. Find the Highest Altitude

19.06.2026 easy 2026 kotlin rust

Max running sum

1732. Find the Highest Altitude easy substack youtube

https://dmitrysamoylenko.com/leetcode/

19.06.2026.webp

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/1395

Problem TLDR

Max running sum

Intuition

Simulate. Take max.

Approach

  • Kotlin: scan, Int::plus
  • Rust: fold

Complexity

  • Time complexity: \(O(n)\)

  • Space complexity: \(O(1|n)\)

Code

    fun largestAltitude(g: IntArray) =
    g.scan(0, Int::plus).max()
    pub fn largest_altitude(g: Vec<i32>) -> i32 {
        g.iter().fold((0,0), |(r,h), x| (r.max(h+x), h+x)).0
    }

Comments