2123. The Number of Weak Characters in the Game
My accepted Python solution to LeetCode problem 2123, The Number of Weak Characters in the Game, running in 251ms.
- Difficulty: Medium
- Python
- Runtime 251ms
- Memory 58.5MB
- 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 251ms, memory 58.5MB, accepted 2025-12-29.
class Solution:
def numberOfWeakCharacters(self, properties: List[List[int]]) -> int:
# Sort by attack descending, then by defense ascending
properties.sort(key=lambda x: (-x[0], x[1]))
count = 0
max_defense = 0
for attack, defense in properties:
if defense < max_defense:
count += 1
else:
max_defense = defense
return count