From 1609c46b281f0b192d3ef7e9f5611d8578e97b7b Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Wed, 8 Oct 2025 00:32:05 +0000 Subject: [PATCH] https://leetcode.com/problems/successful-pairs-of-spells-and-potions --- .../successful_pairs_of_spells_and_potions.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 medium/successful_pairs_of_spells_and_potions.py 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 +