aboutsummaryrefslogtreecommitdiff
path: root/find_min_amount_brew_potion.py
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-10-08 18:28:37 -0600
committerJack Sangdahl <[email protected]>2025-10-08 18:28:37 -0600
commitb69b6266df7de0ab483d81ba6c9f5fa507aa8972 (patch)
treeee2de0a6ab220edadec13f1e21c8a25ab63201f6 /find_min_amount_brew_potion.py
parentf3e447ec79036fda15e973ff7d0ea81cbebb4532 (diff)
downloadleetcode-b69b6266df7de0ab483d81ba6c9f5fa507aa8972.tar.gz
leetcode-b69b6266df7de0ab483d81ba6c9f5fa507aa8972.zip
3494. find the minimum amount of time to brew potions
Diffstat (limited to 'find_min_amount_brew_potion.py')
-rw-r--r--find_min_amount_brew_potion.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/find_min_amount_brew_potion.py b/find_min_amount_brew_potion.py
new file mode 100644
index 0000000..ab0c6a6
--- /dev/null
+++ b/find_min_amount_brew_potion.py
@@ -0,0 +1,37 @@
+# 3494. Find the Minimum Amount of Time to Brew Potions
+from itertools import accumulate
+
+"""
+you are given two integer arrays 'skill' and 'mana' of length 'n' and 'm'
+respectively. in a laboratory, 'n' wizards must brew 'm' potions in order.
+each potion has a mana capacity 'mana[j]' and must pass through all the
+wizards sequentially to be brewed properly. the time taken by the i'th wizard
+on the j'th potion is 'time_ij = skill[i] mana[j]'. since the brewing
+process is delicate, a potion must be passed to the next wizard immediately
+after the current wizard completes their work. this means the timing must be
+synchronised so that each wizard begins working on a potion exactly when it
+arrives. return the minimum amount of time required for the potions to be
+brewed properly.
+"""
+
+
+class Solution(object):
+ def minTime(self, skill, mana):
+ """
+ :type skill: List[int]
+ :type mana: List[int]
+ :rtype: int
+ """
+ acc, t = list(accumulate(skill, initial=0)), 0
+ for j in range(1, len(mana)):
+ t += max(
+ mana[j - 1] * acc[i + 1] - mana[j] * acc[i] for i in range(len(skill))
+ )
+ return t + acc[-1] * mana[-1]
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.minTime(skill=[1, 5, 2, 4], mana=[5, 1, 4, 2]))
+ print(obj.minTime(skill=[1, 1, 1], mana=[1, 1, 1]))
+ print(obj.minTime(skill=[1, 2, 3, 4], mana=[1, 2]))