diff --git a/python/successfull_pairs_of_spells_and_potions.py b/python/successfull_pairs_of_spells_and_potions.py new file mode 100644 index 0000000..fd5ad16 --- /dev/null +++ b/python/successfull_pairs_of_spells_and_potions.py @@ -0,0 +1,8 @@ +# https://leetcode.com/problems/successful-pairs-of-spells-and-potions/editorial/ +# T: O((n + m)logm) where n is the number of spells and m is the number of potions +# S: O(m) where m is the number of potions + +class Solution: + def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]: + potions.sort() + return [len(potions) - bisect_left(potions, (success + x - 1) // x) for x in spells]