Java Solution: class Solution { public int[] successfulPairs(int[] spells, int[] potions, long success) { Arrays.sort(potions); // Sort the potions array for binary search int n = potions.length; // Total number of potions int[] res = new int[spells.length]; // Result array to store the count of successful pairs for (int i = 0; i < spells.length; i++) { int spell = spells[i]; int l = 0, u = n - 1; // Initialize binary search boundaries while (l
@indiccoder12 күн бұрын
CPP Solution: class Solution { public: vector successfulPairs(vector& spells, vector& potions, long long success) { sort(potions.begin(), potions.end()); // Sort the potions array for binary search int n = potions.size(); // Total number of potions vector res; // Result vector to store the count of successful pairs for (int spell : spells) { int l = 0, u = n - 1; // Initialize binary search boundaries while (l
@indiccoder12 күн бұрын
Python Solution: class Solution: def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]: potions.sort() # Sort the potions array for binary search n = len(potions) # Total number of potions res = [] # Result array to store the number of successful pairs for each spell for spell in spells: l, u = 0, n-1 # Initialize binary search boundaries while l