2919. Maximum Number of Groups With Increasing Length
My accepted Python solution to LeetCode problem 2919, Maximum Number of Groups With Increasing Length, running in 158ms.
- Difficulty: Hard
- Python
- Runtime 158ms
- Memory 31.2MB
- 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 158ms, memory 31.2MB, accepted 2026-01-01.
class Solution:
def maxIncreasingGroups(self, usageLimits: List[int]) -> int:
usageLimits.sort()
groups = 0
total = 0
for limit in usageLimits:
total += limit
# Can we form one more group?
# Need 1+2+...+(groups+1) total elements
needed = (groups + 1) * (groups + 2) // 2
if total >= needed:
groups += 1
return groups