3351. Maximize Happiness of Selected Children
My accepted Python solution to LeetCode problem 3351, Maximize Happiness of Selected Children, running in 853ms.
- Difficulty: Medium
- Python
- Runtime 853ms
- Memory 44.1MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 853ms, memory 44.1MB, accepted 2025-12-30.
class Solution:
def maximumHappinessSum(self, happiness: List[int], k: int) -> int:
happiness.sort(reverse=True)
result = 0
for i in range(k):
result += max(0, happiness[i] - i)
return result