JS, binary search with comments
Intuition\nTo achieve we don\'t have to calcualate every spell * potion. If we sort potions then have to find the firs potion which satisfies our conditions. Al
# Intuition\nTo achieve we don\'t have to calcualate every spell * potion. If we sort potions then have to find the firs potion which satisfies our conditions. All next potions will satisfy as well.\n\n# Approach\n - Sort potions ascending order\n - for each spell find that minimum number which would be bigger than success after multiplying on it\n - find the index of the first potion which is equal or more than that number\n\n# Complexity\n- Time complexity: O(n*log(n) + n*log(m))\n\n- Space complexity: O(1)\n\n# Code\n```\n/**\n * @param {number[]} spells\n * @param {number[]} potions\n * @param {number} success\n * @return {number[]}\n */\nvar successfulPairs = function(spells, potions, success) {\n    // Sort potions asc order for binary search\n    potions.sort((a, b) => a - b);\n    const ans = [];\n    for (const spell of spells) {\n        // this number will help us to find the index of the first potion which is equal or more than that number\n        const rel = success / spell;\n        let left = 0, right = potions.length - 1;\n        // standard binary search\n        while (left <= right) {\n            const mid = Math.floor((left + right) / 2);\n            if (potions[mid] < rel) {\n                left = mid + 1;\n            } else {\n                right = mid - 1;\n            }\n        }\n        // the answer for this number would be the difference between the potions leng and the index\n        ans.push(potions.length - left);\n    }\n    return ans;\n};\n```
['JavaScript']