LeetCode solutions

2279. Maximum Split of Positive Even Integers

My accepted Python solution to LeetCode problem 2279, Maximum Split of Positive Even Integers, running in 63ms.

  • Difficulty: Medium
  • Python
  • Runtime 63ms
  • Memory 26.9MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 63ms, memory 26.9MB, accepted 2026-01-02.

python
class Solution:
    def maximumEvenSplit(self, finalSum: int) -> List[int]:
        if finalSum % 2 == 1:
            return []
        
        result = []
        current = 2
        remaining = finalSum
        
        while remaining >= current:
            if remaining - current > current:  # Can still add more
                result.append(current)
                remaining -= current
                current += 2
            else:
                # remaining will be added to result as the last element
                result.append(remaining)
                break
        
        return result

Source