C++ solution || with explanation || Let's code it💻
Upvote if you found this solution helpful\uD83D\uDD25\n\n# Approach\nThe first approach which comes to mind after reading the question is to traverse the Potion
# Upvote if you found this solution helpful\uD83D\uDD25\n\n# Approach\nThe first approach which comes to mind after reading the question is to traverse the Potions array for each spell and count the number of pairs which satisfies the given condition, but this method leads to TLE because the time complexity for this will be O(n x m) where both n and m are of order 10^5.\nSo, the optimized approach is to reduce the number of calculations we are doing for each spell.\nIf we think for second we can deduce that by sorting the list of potions and using binary search to traverse the list we can reduce our calculations in a significant way.\n\nNOTE: Keep in mind to convert the product of spell and potion to LONG LONG before further moving with calculations\n\n# Code\n```\nclass Solution {\npublic:\n\n    int countPairs(int spell, vector<int> &potions, long long success){\n        int n = potions.size();\n        int index = n;\n        int start = 0;\n        int end = n-1;\n\n        while(start <= end){\n            int mid = start + (end-start)/2;\n\n            //if the product of potion and spell satisfies the condition, move the end pointer to mid-1 because we need to find the first element for which the product of spell and potion is greater than success\n            if((long long)potions[mid]*spell >= success){\n                index = mid;\n                end = mid-1;\n            }\n\n            //if the product is less than the success value move to start pointer to mid+1\n            if((long long)potions[mid]*spell < success)\n                start = mid+1;\n        }\n\n        return n-index;\n    }\n\n    vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n        vector<int> ans(spells.size());\n\n        //sorting the potions list\n        sort(potions.begin(), potions.end());\n\n        //for each spell find the number of potions which can satisfy the condition\n        for(int i=0; i<spells.size(); i++)\n            ans[i] = countPairs(spells[i], potions, success);\n\n        return ans;\n    }\n};\n```
['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'C++']