Solution By Dare2Solve | Detailed Explanation | Clean Code
Explanation []\nauthorslog.com/blog/ZzthSLHX8W\n\n# Code\n\ncpp []\nclass Solution {\npublic:\n    vector<int> successfulPairs(vector<int>& spells, vector<int>&
```Explanation []\nauthorslog.com/blog/ZzthSLHX8W\n```\n# Code\n\n```cpp []\nclass Solution {\npublic:\n    vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n        vector<long long> arr; // Use long long to handle large numbers\n        for (int potion : potions) {\n            arr.push_back(ceil(success / (double)potion)); // Ensure double division for accurate results\n        }\n        sort(arr.begin(), arr.end());\n\n        vector<int> res;\n        for (int spell : spells) {\n            int l = 0, r = arr.size() - 1, M = 0;\n            while (l <= r) {\n                int m = l + (r - l) / 2;\n                if (arr[m] <= spell) {\n                    l = m + 1;\n                    M = l;\n                } else {\n                    r = m - 1;\n                }\n            }\n            res.push_back(M);\n        }\n\n        return res;\n    }\n};\n\n```\n\n```python []\nclass Solution:\n    def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n        arr = [math.ceil(success / potion) for potion in potions]\n        arr.sort()\n\n        res = []\n        for spell in spells:\n            l, r, M = 0, len(arr) - 1, 0\n            while l <= r:\n                m = (l + r) // 2\n                if arr[m] <= spell:\n                    l = m + 1\n                    M = l\n                else:\n                    r = m - 1\n            res.append(M)\n\n        return res\n\n```\n\n```java []\nclass Solution {\n    public int[] successfulPairs(int[] spells, int[] potions, long success) {\n        List<Long> arr = new ArrayList<>();\n        for (int potion : potions) {\n            arr.add((long) Math.ceil((double) success / potion)); // Use long for large numbers\n        }\n        Collections.sort(arr);\n\n        int[] res = new int[spells.length];\n        for (int i = 0; i < spells.length; i++) {\n            int spell = spells[i];\n            int l = 0, r = arr.size() - 1, M = 0;\n            while (l <= r) {\n                int m = l + (r - l) / 2;\n                if (arr.get(m) <= spell) {\n                    l = m + 1;\n                    M = l;\n                } else {\n                    r = m - 1;\n                }\n            }\n            res[i] = M;\n        }\n\n        return res;\n    }\n}\n\n```\n\n```javascript []\nvar successfulPairs = function(spells, potions, success) {\n    let arr = [];\n    for(let potion of potions) {\n        arr.push(Math.ceil(success / potion));\n    }\n    arr.sort((a,b) => a-b);\n    const n = arr.length;\n    console.log(arr);\n\n    const res = [];\n    for(let spell of spells) {\n        let l=0, r=n-1, M=0;\n        while(l<=r) {\n            let m = Math.floor((l+r)/2);\n            if(arr[m] <= spell) {\n                l = m+1;\n                M = l;\n            } else {\n                r = m-1;\n            }\n        }\n        res.push(M);\n    }  \n    return res;\n};\n```
['Array', 'Two Pointers', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']