LeetCode solutions

2066. Add Minimum Number of Rungs

My accepted Python solution to LeetCode problem 2066, Add Minimum Number of Rungs, running in 8ms.

  • Difficulty: Medium
  • Python
  • Runtime 8ms
  • Memory 30.6MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 8ms, memory 30.6MB, accepted 2025-12-29.

python
class Solution:
    def addRungs(self, rungs: List[int], dist: int) -> int:
        count = 0
        prev = 0
        for rung in rungs:
            gap = rung - prev
            if gap > dist:
                count += (gap - 1) // dist
            prev = rung
        return count

Source