Trains the technique from
LeetCode 343Integer BreakThis 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 supplier holds a single rod of length n centimetres and has to saw it into two or more pieces. Every piece must be a whole number of centimetres long, and the piece lengths have to add up to exactly n. Pieces may repeat a length, and their order does not matter.
The pieces are then sold as a set priced at the product of their lengths. Return the largest product any allowed set of pieces can reach.
Example 1
Cutting the rod into pieces of 3 and 4 gives lengths that add to 7 and a product of 12.
Example 2
Cutting into 2 and 2 gives a product of 4, and the two pieces add up to 4.
Example 3
One allowed set is thirteen pieces of 3 and one piece of 4, which add up to 43 and multiply to 6377292.
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 integer_break(n: int) -> int:public int integerBreak(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.