From 0a4126e7b2a08ee56dd4fd56dcc94b1728dd2679 Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Wed, 4 Jan 2023 12:26:44 -0500 Subject: [PATCH] Time: 2311 ms (27.08%), Space: 26.6 MB (64.58%) - LeetHub --- ...44-minimum-rounds-to-complete-all-tasks.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 2244-minimum-rounds-to-complete-all-tasks/2244-minimum-rounds-to-complete-all-tasks.py diff --git a/2244-minimum-rounds-to-complete-all-tasks/2244-minimum-rounds-to-complete-all-tasks.py b/2244-minimum-rounds-to-complete-all-tasks/2244-minimum-rounds-to-complete-all-tasks.py new file mode 100644 index 0000000..ff00e98 --- /dev/null +++ b/2244-minimum-rounds-to-complete-all-tasks/2244-minimum-rounds-to-complete-all-tasks.py @@ -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 + \ No newline at end of file