---
title: "2300. Successful Pairs of Spells and Potions"
url: "https://laigary.com/interview/coding/2300-successful-pairs-of-spells-and-potions"
type: "note"
section: "coding"
date: "2025-04-10"
updated: "2025-04-10"
tags: ["Binary Search"]
---

# 2300. Successful Pairs of Spells and Potions

[2300\. Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions/)

```python
class Solution:
    def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:
        def search(arr, target):
            left = 0
            right = len(arr)
            while left < right:
                mid = left + (right - left)//2
                if arr[mid] >= target:
                    right = mid
                else:
                    left = mid + 1
            return left
        
        potions.sort()

        res = []
        m = len(potions)
        for spell in spells:
            i = search(potions, success/spell)
            res.append(m - i)
        
        return res
```
