#2178
Maximum Split of Positive Even Integers
specialist · 725 · lc medium +31 · failed · 59.6% accepted · 825 likes · top 57%
Description
You are given an integer finalSum. Split it into the maximum number of distinct positive even integers that sum to finalSum.
- For example, finalSum = 12 has valid splits (12), (2 + 10), (2 + 4 + 6), and (4 + 8). The split (2 + 4 + 6) uses the most integers.
Return a list representing a valid split with the maximum number of integers. If no valid split exists, return an empty list. The integers may be in any order.
Example 1:
Input: finalSum = 12
Output: [2,4,6]
Explanation: The following are valid splits: (12), (2 + 10), (2 + 4 + 6), and (4 + 8).
(2 + 4 + 6) has the maximum number of integers, which is 3. Thus, we return [2,4,6].
Note that [2,6,4], [6,2,4], etc. are also accepted.
Example 2:
Input: finalSum = 7
Output: []
Explanation: There are no valid splits for the given finalSum.
Thus, we return an empty array.
Example 3:
Input: finalSum = 28
Output: [6,8,2,12]
Explanation: The following are valid splits: (2 + 26), (6 + 8 + 2 + 12), and (4 + 24).
(6 + 8 + 2 + 12) has the maximum number of integers, which is 4. Thus, we return [6,8,2,12].
Note that [10,2,4,12], [6,2,4,16], etc. are also accepted.
Code
1
2
3