2392. Successful Pairs of Spells and Potions
My accepted Python solution to LeetCode problem 2392, Successful Pairs of Spells and Potions, running in 162ms.
- Difficulty: Medium
- Python
- Runtime 162ms
- Memory 42.7MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 162ms, memory 42.7MB, accepted 2025-12-29.
class Solution:
def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:
import bisect
potions.sort()
n = len(potions)
result = []
for spell in spells:
# We need spell * potion >= success
# So potion >= success / spell
# Find the minimum potion value that works
min_potion = (success + spell - 1) // spell # Ceiling division
# Find the index of the first potion >= min_potion
idx = bisect.bisect_left(potions, min_potion)
# Count of valid potions
result.append(n - idx)
return result