Python Radix Sort | Beats 99.46%
Intuition\nWe need to evaluate each digit of the numbers differently based on the given mapping. We could convert each number, or we could use the mapping to so
# Intuition\nWe need to evaluate each digit of the numbers differently based on the given mapping. We could convert each number, or we could use the mapping to sort the numbers into appropriate buckets. \n\nI won\'t attempt to explain Radix Sort, as several other sources will explain it better than I will. Once it\'s understood, the application to this problem should become clear.\n\nHere is a two-minute video that explains it pretty well.\n\nhttps://www.youtube.com/watch?v=GUHGMtNo6RQ\n\n# Approach\nWe use a classic radix sort, rather than placing the items in buckets based on their original digits, we use the mapped value.\n\n# Complexity\n- Time complexity:\nO(n * k)\n\n- Space complexity:\nO{n + k}\n\n# Code\n```\nclass Solution:\n    def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:\n        maxNumber = max(nums)\n        maxDigits = len(str(maxNumber))\n\n        for i in range(maxDigits):\n            buckets = [[] for _ in range(10)]\n            tenthPlace =  10**i\n            for number in nums:\n                if number < tenthPlace and i != 0:\n                    buckets[0].append(number)\n                    continue\n                digit = floor(number / tenthPlace) % 10\n                trueValue = mapping[digit]\n                buckets[trueValue].append(number)\n            nums = [num for bucket in buckets for num in bucket]\n\n        return nums\n                \n\n```
['Sorting', 'Radix Sort', 'Python3']