Why and How Binary Search || Intuition Explained
\n\n\n\nclass Solution {\npublic:\n    int getPairCount(vector<int>& potions, int& spell, long long& target)\n    {\n        int n = potions.size(), bestIdx = n
![image](https://assets.leetcode.com/users/images/4bde32d2-e235-415d-8602-368016c3acdb_1680397806.4855666.png)\n![image](https://assets.leetcode.com/users/images/32b4d538-b79a-414b-b799-5195c4622a93_1680398342.075346.png)\n\n```\nclass Solution {\npublic:\n    int getPairCount(vector<int>& potions, int& spell, long long& target)\n    {\n        int n = potions.size(), bestIdx = n;\n        int low = 0, high = n - 1;\n        //=============================================================\n        while(low <= high)\n        {\n            int mid = low + (high - low) / 2;\n            long long product = (long long)spell * potions[mid];\n            \n            if (product >= target)\n            {\n                bestIdx = mid;\n                high = mid - 1;\n            }\n            else low = mid + 1;\n        }\n        //================================================================\n        return (n - bestIdx);\n    }\n    vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success)\n    {\n        int n = spells.size();\n        vector<int>ans(n);\n        sort(potions.begin(), potions.end());\n        for (int i = 0; i < n; i++) \n            ans[i] = getPairCount(potions, spells[i], success);\n        \n        return ans;\n    }\n};\n```\n\n
['C', 'Binary Tree', 'C++']