Ctrl K

Split for the Largest Product

Medium
You are given an integer total. Write it as a sum of **at least two** positive integers so that their product is as large as possible. Return that largest product.
Example 1
total=7 → 12

7 = 3 + 2 + 2 gives 3 · 2 · 2 = 12. For comparison, 3 + 4 also gives 12, while 3 + 3 + 1 gives only 9.

Example 2
total=3 → 2

There must be at least two parts: 3 = 1 + 2, product 2.

Example 3
total=12 → 81

12 = 3 + 3 + 3 + 3, product 81.

Constraints
  • 2 ≤ total ≤ 58
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCounting Grid Routes MediumCounting Search Tree Shapes MediumEvery Bracketing Result MediumNumbers Made of Twos, Threes and Fives MediumFewest Square Terms Medium
loading Python…
Input
total=7
Expected
12

Run checks the first 3 tests in your browser. Submit checks all 33 tests on the server, hidden ones included.