JAVA || Easy Solution Using Binary Search || Beginner friendly || Using Map
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\nPLEASE UPVOTE IF YOU LIKE.\n```\nclass Solution {\n    \n    Map<Integer, int[]> duplicates;\n\n    public int[] successfulPairs(int[] spells, int[] potions, long success) {\n        int[] pairs = new int[spells.length];\n        Arrays.sort(potions);\n        int ind = 0;\n        duplicates = new HashMap<>();\n        for (int i = 0; i < potions.length; i++) {\n            if (duplicates.containsKey(potions[i])) {\n                int[] idx = duplicates.get(potions[i]);\n                duplicates.put(potions[i], new int[]{idx[0], i});\n            } else duplicates.put(potions[i], new int[]{i});\n        }\n\n        for (int s : spells) {\n            int idx = bs(potions, (long) Math.ceil((double) success / s));\n            if (idx >= 0) {\n                pairs[ind++] = potions.length - idx;\n            } else {\n                pairs[ind++] = 0;\n            }\n        }\n        return pairs;\n    }\n\n    private int bs(int[] potions, long value) {\n        int l = 0, h = potions.length - 1;\n        while (l < h) {\n            int mid = l + (h - l) / 2;\n            if (value < potions[mid]) {\n                h = mid;\n            } else if (value > potions[mid]) {\n                l = mid + 1;\n            } else if (value == potions[mid]) {\n                return duplicates.get(potions[mid])[0];\n            }\n        }\n\n        return potions[l] < value ? -1 : l;\n    }\n}\n```
['Java']