Sorting + Binary Search + Explaination||✅Easy Java solution||Beginner Friendly🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nSort the potions array and then use binary search on potions array to get the that elem
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSort the potions array and then use binary search on potions array to get the that element whose elements of right part of the array will be greater than or equal to success given because if that particular element excceds success then all element from right will be also excceds.\n\n# Code\n```\nclass Solution {\n    public int[] successfulPairs(int[] spells, int[] potions, long success) {\n        int n = spells.length;\n        int m = potions.length;\n        int ans[] = new int[n];\n        Arrays.sort(potions);\n        for(int i = 0 ; i < n; i ++){\n            int spell = spells[i];\n            int low = 0;\n            int high = m - 1;\n            while(low <= high){\n                int mid = (high - low)/2 + low;\n                long product = (long)spell * (long)potions[mid];\n                if(product >= success){\n                    high = mid - 1;\n                }else{\n                    low = mid + 1;\n                }\n            }\n            ans[i] = m - low;\n        }\n        return ans;\n    }\n}\n```
['Binary Search', 'Sorting', 'Java']