Trains the technique from
LeetCode 2742Painting the WallsThis 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 gallery has n panels waiting to be restored and a shortlist of exactly n paid restorers, both numbered 0 through n - 1. Restorer i needs hours[i] whole hours to bring one panel back and charges fee[i] for the job. A restorer may be hired for at most one panel, and you may hire as few or as many of them as you like.
One volunteer is also available. The volunteer restores a panel in exactly one hour and charges nothing.
The work runs in whole hours, one after another. The paid restorers you hire work in sequence, in whatever order you choose, each occupying the workshop for their own number of hours. The volunteer may work during an hour when a paid restorer is at work in the workshop, restoring one panel in that hour, and may not work during any other hour.
Every panel has to be restored by exactly one worker, paid or volunteer. Return the smallest total fee that gets all n panels restored.
Example 1
Hire restorer 0 alone for 3. It restores one panel and occupies the workshop for 8 hours, and the volunteer restores the other three panels in three of those hours.
Example 2
Hire restorer 1 for 100. It restores one panel and holds the workshop for 100 hours, and the volunteer restores the remaining panel in the first of them.
Example 3
There is one panel and the volunteer cannot work unless a paid restorer is in the workshop, so restorer 0 has to be hired for 7.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def least_restoration_fee(fee: list[int], hours: list[int]) -> int:public int leastRestorationFee(int[] fee, int[] hours)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.