Ctrl K

Most Distinct Even Parts

Medium
You get a positive integer total. Write it as a sum of **pairwise distinct** positive even numbers using as many parts as possible. If several splits reach that maximum number of parts, pick the one whose largest part is as big as possible. Return its parts in ascending order. If total cannot be split this way, return an empty list.
Example 1
total=20 → [2, 4, 6, 8]

Five distinct even parts add up to at least 2 + 4 + 6 + 8 + 10 = 30 > 20, so four is the most: 2 + 4 + 6 + 8 = 20.

Example 2
total=16 → [2, 4, 10]

More than three parts is impossible (2 + 4 + 6 + 8 = 20 > 16). There are two three-part splits, 2 + 4 + 10 and 2 + 6 + 8; the first has the larger biggest part.

Example 3
total=9 → []

A sum of even numbers is always even, so 9 cannot be split.

Constraints
  • 1 ≤ total ≤ 10¹⁰
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsZero-Free Number With a Multiple Digit Product HardMirrored One-Bit Codes MediumNumbers Without Repeated Digits MediumSmallest Number From Digit Factors MediumOne Digit Swap Medium
loading Python…
Input
total=20
Expected
[2, 4, 6, 8]

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