Python||Binary Search||Explanation
I Was Also One Of The Person Who Got TLE At The First Attempt\n\nThe Straight Forward Approach was to multiply each and every value of potion with the every val
I Was Also One Of The Person Who Got TLE At The First Attempt\n\nThe Straight Forward Approach was to multiply each and every value of potion with the every value of spell and count the values which are greater than success and append to the answer array. This was one of the common solution which every one thinks of..\n\nThe Solution For Me Which Got Accepted Was After Using Binary Search With Sorting Array.\n\nLet Us See How It Worked For Me..\n\nSuppose spell = [5,1,3] potions = [1,2,3,4,5]  success = 7\n\nConsider First Element Of Spell - 5  the least number that makes 5 after multiplying results to greater than or equal to  7 that is obviously 2 - So the resultant value will be 4 \n\nConsider Second Element Of Spell -1 The Smallest Number That Makes Greater Than or equal to 7 is 7 but it is not in the array so the resultant value will be 0\n\nConsider Last Element Of Spell - 3 The Smallest Number That Makes 3 Greater Than Or Equal To 7 is 3 - So the Resultant Value will be 3\n\nSimilarly For Every Value in Spell If We Are Able To Find The Smaller Value Which After Multiplying Makes Greater Than Success Value And Then We Had To Find The Left Most Index Which Will Be Suitable For Placing The Obtained Value In The Potions Will Result Us Answer.\n\nThis is my following Code For The Problem..\n\n```\nclass Solution:\n    def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n        result = self.function(spells,potions,success)\n        return result\n    \n    def function(self,arr1,arr2,success):\n        n2 = len(arr2)\n        arr2.sort() #Sorting Enables Us To Do Binary Search\n        ans = []\n        for i in arr1:\n            val = math.ceil(success/i) #Finding the Value Of Portion With Least Strength So That It Can Be Greater Than Success\n            idx = bisect.bisect_left(arr2,val) #Finding The Left Most Index So That The Value Can Be Inserted\n            res = n2-idx+1  #Calculating the remaining numbers after finding the suitable index\n            ans.append(res-1)\n        return ans\n```\n\nPlease Upvote If You Like The Explanation..\uD83D\uDE0A\n\n\nHappy LeetCoding!!!!
['Sorting', 'Binary Tree', 'Python']