Time: 2311 ms (27.08%), Space: 26.6 MB (64.58%) - LeetHub

This commit is contained in:
Deven
2023-01-04 12:26:44 -05:00
parent 957d54dc31
commit 0a4126e7b2
@@ -0,0 +1,29 @@
class Solution(object):
def minimumRounds(self, tasks):
"""
:type tasks: List[int]
:rtype: int
"""
# Counts the number of iterations of each difficulty
countByDifficulty = {}
for dif in tasks:
if dif not in countByDifficulty:
countByDifficulty[dif] = 0
countByDifficulty[dif] += 1
# Count the amount of rounds required to complete
roundsRequired = 0
for count in countByDifficulty.values():
if count == 1:
return -1
if count % 3 == 0:
roundsRequired += count / 3
else:
## Examples: 7 (rem 1), 8 (rem 2)
# 7 = 3+2+2
# 8 = 3+3+2
roundsRequired += int(count / 3) + 1
return roundsRequired