2300. Successful Pairs of Spells and Potions
https://leetcode.com/problems/successful-pairs-of-spells-and-potions
Python
Sort and Binary Search
from bisect import bisect_left
class Solution:
def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:
potions.sort()
result = []
for spell in spells:
pos = bisect_left(
potions,
success,
key=lambda position: position*spell
)
result.append(len(potions)-pos)
return result