Trains the technique from
LeetCode 2366Minimum Replacements to Sort the ArrayThis 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 freight manifest lists crate weights in loading order as weights. The loader will only accept the manifest when the weights never decrease as you read it from the first entry to the last.
One cut takes a single crate of weight w and replaces it with two crates whose weights are positive whole numbers adding up to w. The two new crates take the cut crate's place in the manifest, one after the other, so the manifest gets one entry longer. Either of the new crates may be cut again later.
Return the least number of cuts that makes the manifest never decrease.
Example 1
Cut the 8 into 4 and 4, then cut the 12 into 4 and 8 and cut that 8 into 4 and 4. The manifest now reads 4, 4, 4, 4, 4, 6, which never decreases, after three cuts.
Example 2
Three cuts turn the 10 into 2, 2, 3 and 3, leaving the manifest reading 2, 2, 3, 3, 3, 3, which never decreases.
Example 3
The manifest already never decreases, so no cut is needed.
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_crate_splits(weights: list[int]) -> int:public long minCrateSplits(int[] weights)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.