hashmap + stack approach  Beats 99.87% + Explaination 🔥✅
\n# Approach\n So we need to sort the potion array , why ? Because when we loop through the  potion array we want to store the number of integers are infront of
\n# Approach\n So we need to sort the ```potion``` array , why ? Because when we loop through the  ``` potion``` array we want to store the number of integers are infront of `potion[i]` \n\nFor Example: ```potions = [5,2,4,3,1]``` \nWhen we sort it we get this ```[1,2,3,4,5]```\nNow we know that 5 numbers are greater or equal to number ``1`` \nAnd we know that 4 numbers are greater or equal to number ```2```\nAlso we know that 3 numbers are greater or equal to number ```3```\nAnd so on...\nWhy is this important ? Let me explain\n\nLets say ```spells = [5,1,3], potions = [1,1,3,4,5], success = 7```\nand our ```spell[i] = 5``` \nset our bar  = ```success / spell[i]``` so ```bar = 7 / 5 | 1.4``` then we know that our ```potion[i]``` have to be greater or equal to ```bar``` in order to succeed, since we are working with integers and not float then we can use ```ceil``` to round it up so ```bar = 2```\n\nNow our ```1st``` for loop should cause our hashmap to look like this  ```hashmap = {1: 5, 3: 3, 4: 2, 5: 1}``` keep in mind ```trace```,  it will be use to store the order of the sorted number. We\'ll use ```trace``` later in the ```2nd``` for loop.\n\nNow to make our ```lookup``` variable in the  ```2nd``` for loop , this variable will be use to store how many integers are in front of bar if ```bar = i```.\n\nNow our lookup look like this ```lookup = [5,5,3,3,2,1] ```\nBoom youre done \u2705 now we can loop through ```spell```\n\n ```spell[0] = 5``` Now we have to set our bar to, ```bar = ceil(7 / 5 | 1.4) = 2``` Now we go to ```lookup[2] = 3``` which means if the ```bar = 2``` then 3 integers are greater or equal to 2, If the bar is greater then the length of ```lookup``` that means ```0``` integers are greater or equal to the bar so we add ```0``` in our ```stack``` if the bar is a negative number then we know that ```all``` of our integers is greater than the bar so we can add ```lookup[0] | len(potions) ```\n\n\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:\n        potions.sort()\n        pointer = 0\n        trace = []\n        hashmap ={}\n        stack = []\n        length = len(potions)\n        lookup = []\n        \n\n        for idx, num in enumerate(potions):\n            if num in hashmap:\n                continue\n            hashmap[num] = length - idx\n            trace.append(num)\n        \n        for i in range(potions[-1] + 1):\n            Pnum = trace[pointer]\n            if i not in hashmap:\n                \n                lookup.append(hashmap[Pnum])\n                continue\n            \n            lookup.append(hashmap[Pnum])\n            pointer +=1\n     \n        for spell in spells:\n            bar = ceil(success / spell)\n            if bar > len(lookup) - 1:\n                stack.append(0)\n            elif bar < 0:\n                stack.append(lookup[0])\n            else:\n                stack.append(lookup[bar])\n\n        return stack\n\n\n```
['Hash Table', 'Stack', 'Python3']