Java | Binary Search | Clean code | Beats > 87%
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: $$O((m+n) * log(m))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(log(m))$$ used by the sort algorithm in Java\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  public int[] successfulPairs(int[] spells, int[] potions, long success) {\n    var n = spells.length;\n    var m = potions.length;\n    var pairs = new int[n];\n    \n    Arrays.sort(potions);\n\n    for (var i=0; i<n; i++) {\n      var minPotion = (int) Math.ceil((double) success / spells[i]);\n\n      if (minPotion > potions[m-1]) continue;\n\n      var l = 0;\n      var r = m-1;\n\n      while (l < r) {\n        var mid = l + (r-l) / 2;\n\n        if (potions[mid] < minPotion) l = mid+1;\n        else r = mid;\n      }\n      pairs[i] = m-l;\n    }\n    return pairs;\n  }\n}\n```\nIf you like my solution, please upvote it!
['Array', 'Binary Search', 'Sorting', 'Java']