Trains the technique from
LeetCode 1547Minimum Cost to Cut a StickThis 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 mill receives a bolt of cloth length centimetres long and has to divide it at every mark in marks. A mark is written as its distance in centimetres from the left end of the bolt, so every mark sits strictly inside the cloth.
Cutting is done one pass at a time. A pass takes a single piece of cloth, feeds it through the blade at one of the marks still lying inside that piece, and hands back the two pieces either side of it. The mill bills a pass at the width of the piece that went in, no matter where within it the mark sat, and the bill for the job is the sum over all passes.
The passes may be made in any order you like, and the order matters, because a piece already divided is narrower for later passes.
Return the smallest total bill for dividing the bolt at every mark.
Example 1
Passing at 3 bills 7 and leaves pieces 0-3 and 3-7; passing at 1 bills 3, at 5 bills 4, and at 4 bills 2, for 7 + 3 + 4 + 2 = 16.
Example 2
There is a single mark and a single pass, and the piece fed in is the whole bolt.
Example 3
Passing at 2 bills 20 and passing at 19 then bills 18, for a total of 38.
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 min_cutting_charge(length: int, marks: list[int]) -> int:public int minCuttingCharge(int length, int[] marks)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.