All problems
0231EasyArrayDynamic Programming

Ladder Rung Repair Fees

Tracked in this browser only
Write code

Trains the technique from

LeetCode 746Min Cost Climbing Stairs

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A maintenance crew has to get up and over a service ladder whose rungs each need patching before they will take weight. The array fees holds the patching charge for every rung, counted from the bottom, so fees[i] is billed the moment a climber rests on rung i.

A climber opens the ascent by resting on rung 0 or on rung 1, whichever they prefer, and is billed for that rung. From whatever rung they are on, the next move lifts them one rung or two rungs higher. The ascent is over as soon as a move carries the climber past the highest rung, and clearing the ladder is not billed.

Return the smallest total charge for an ascent that gets past the top.

Examples

Example 1

Input
fees = [9, 1, 1]
Output
1

The climber opens on rung 1 and is billed 1, then a two-rung move carries them past rung 2, which is the top of this ladder. Nothing more is billed.

Example 2

Input
fees = [1, 2, 3, 100, 1]
Output
5

Resting on rungs 0, 2 and 4 is billed 1 + 3 + 1 = 5, and one more move from rung 4 clears the ladder.

Example 3

Input
fees = [4, 3, 2, 6]
Output
5

Resting on rung 1 and then rung 2 is billed 3 + 2 = 5, and a two-rung move from rung 2 carries the climber past rung 3.

Constraints

  • 2 <= fees.length <= 1000
  • 0 <= fees[i] <= 999

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def cheapest_rung_climb(fees: list[int]) -> int:
Java
public int cheapestRungClimb(int[] fees)
September 7
Apply