2178. Maximum Split of Positive Even Integers Medium

@problem@discussion
#Math#Greedy



1/**
2 * [2178] Maximum Split of Positive Even Integers
3 *
4 * You are given an integer finalSum. Split it into a sum of a maximum number of unique positive even integers.
5 * 
6 * 	For example, given finalSum = 12, the following splits are valid (unique positive even integers summing up to finalSum): (12), (2 + 10), (2 + 4 + 6), and (4 + 8). Among them, (2 + 4 + 6) contains the maximum number of integers. Note that finalSum cannot be split into (2 + 2 + 4 + 4) as all the numbers should be unique.
7 * 
8 * Return a list of integers that represent a valid split containing a maximum number of integers. If no valid split exists for finalSum, return an empty list. You may return the integers in any order.
9 *  
10 * Example 1:
11 * 
12 * Input: finalSum = 12
13 * Output: [2,4,6]
14 * Explanation: The following are valid splits: (12), (2 + 10), (2 + 4 + 6), and (4 + 8).
15 * (2 + 4 + 6) has the maximum number of integers, which is 3. Thus, we return [2,4,6].
16 * Note that [2,6,4], [6,2,4], etc. are also accepted.
17 * 
18 * Example 2:
19 * 
20 * Input: finalSum = 7
21 * Output: []
22 * Explanation: There are no valid splits for the given finalSum.
23 * Thus, we return an empty array.
24 * 
25 * Example 3:
26 * 
27 * Input: finalSum = 28
28 * Output: [6,8,2,12]
29 * Explanation: The following are valid splits: (2 + 26), (6 + 8 + 2 + 12), and (4 + 24). 
30 * (6 + 8 + 2 + 12) has the maximum number of integers, which is 4. Thus, we return [6,8,2,12].
31 * Note that [10,2,4,12], [6,2,4,16], etc. are also accepted.
32 * 
33 *  
34 * Constraints:
35 * 
36 * 	1 <= finalSum <= 10^10
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/maximum-split-of-positive-even-integers/
42// discuss: https://leetcode.com/problems/maximum-split-of-positive-even-integers/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn maximum_even_split(final_sum: i64) -> Vec<i64> {
48        
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_2178() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.