diff --git a/medium/successful_pairs_of_spells_and_potions.py b/medium/successful_pairs_of_spells_and_potions.py new file mode 100644 index 0000000..cbbe368 --- /dev/null +++ b/medium/successful_pairs_of_spells_and_potions.py @@ -0,0 +1,20 @@ +# https://leetcode.com/problems/successful-pairs-of-spells-and-potions + +from typing import List + +class Solution: + def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]: + potions.sort() + for i in range(len(spells)): + spell = spells[i] + left = 0 + right = len(potions) - 1 + while left <= right: + mid = (left + right) // 2 + if spell * potions[mid] >= success: + right = mid - 1 + else: + left = mid + 1 + spells[i] = len(potions) - left + return spells +