2664. Maximize Greatness of an Array
My accepted Python solution to LeetCode problem 2664, Maximize Greatness of an Array, running in 34ms.
- Difficulty: Medium
- Python
- Runtime 34ms
- Memory 30.7MB
- 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 34ms, memory 30.7MB, accepted 2025-12-31.
class Solution:
def maximizeGreatness(self, nums: List[int]) -> int:
# Sort and greedily match
nums.sort()
greatness = 0
j = 0 # Pointer to elements being beaten
for i in range(len(nums)):
if nums[i] > nums[j]:
greatness += 1
j += 1
return greatness