Trains the technique from
LeetCode 3857Minimum Cost to Split into OnesThis 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 single pile holds n tokens.
One break takes a pile holding at least two tokens and divides it into two piles, each holding at least one token, at a cost equal to the size of the pile being broken. Breaks continue until every pile holds a single token.
Return the least total cost of getting there.
Example 1
Breaking the seven into three and four costs 7. The three then costs 5 and the four costs 8, coming to 20. Peeling single tokens off instead would cost 7 plus 6 plus 5 plus 4 plus 3 plus 2, which is 27.
Example 2
The pile already holds a single token, so nothing needs breaking.
Example 3
Halving all the way down costs 8, then two piles of four at 4 each, then four piles of two at 2 each, coming to 24.
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_cost(n: int) -> int:public int minCost(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.