LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 853ms, memory 44.1MB, accepted 2025-12-30.

python
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

Source