💢☠💫Easiest👾Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 💯
Intuition\n\nC++ []\n// Start Of Anuj Bhati aka Edwards310\'s Template...\n#include <bits/stdc++.h>\nusing namespace std;\nusing namespace __gnu_pbds;\ntypedef 
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/8744ddca-35d2-49e5-be82-ba1798e09ea0_1721801637.4529185.jpeg)\n```C++ []\n// Start Of Anuj Bhati aka Edwards310\'s Template...\n#include <bits/stdc++.h>\nusing namespace std;\nusing namespace __gnu_pbds;\ntypedef long long LL;\ntypedef vector<int> vi;\ntypedef pair<int, int> pii;\ntypedef vector<pii> vpii;\n#define FOR(a, b, c) for (int a = b; a < c; a++)\n#define Rep(i, n) FOR(i, 0, n)\n#define fi first\n#define se second\n#define pb push_back\n#define ALL(v) v.begin(), v.end()\n#define SORT(v) sort(ALL(v))\n#define REVERSE(v) reverse(ALL(v))\n// end of Anuj Bhati\'s aka Edwards310\'s Template\nclass Solution {\npublic:\n    vector<int> sortJumbled(vector<int>& mapping, vector<int>& nums) {\n        vpii storePairs;\n        Rep(i, nums.size()) {\n            int mappedValue = 0;\n            int temp = nums[i];\n            int place = 1;\n            if (temp == 0) {\n                storePairs.pb({mapping[0], i});\n                continue;\n            }\n\n            while (temp) {\n                mappedValue = place * mapping[temp % 10] + mappedValue;\n                place *= 10;\n                temp /= 10;\n            }\n            storePairs.pb({mappedValue, i});\n        }\n        SORT(storePairs);\n        vi answer;\n        for (auto pair : storePairs)\n            answer.pb(nums[pair.se]);\n        return answer;\n    }\n};\n```\n```python3 []\nclass Solution:\n    def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:\n        maps = []\n        for i in nums:\n            t = ""\n            for j in str(i):\n                t += str(mapping[int(j)])\n            maps.append(int(t))\n        print(maps)\n        indexes = sorted(range(len(maps)), key=maps.__getitem__)\n        nums = list(map(nums.__getitem__, indexes))\n\n        return nums\n```\n```Java []\nclass Solution {\n    public int[] sortJumbled(int[] mapping, int[] nums) {\n        // Step 1: Create a list to store original nums and their mapped values\n        List<int[]> mappedList = new ArrayList<>();\n        for (int i = 0; i < nums.length; i++) {\n            String s = Integer.toString(nums[i]);\n            StringBuilder n = new StringBuilder();\n            for (char ch : s.toCharArray()) {\n                n.append(mapping[ch - \'0\']);\n            }\n            mappedList.add(new int[] { nums[i], Integer.parseInt(n.toString()), i });\n        }\n\n        // Step 2: Sort the list based on the mapped values and original indices for\n        // stability\n        mappedList.sort((a, b) -> {\n            if (a[1] != b[1]) {\n                return Integer.compare(a[1], b[1]);\n            } else {\n                return Integer.compare(a[2], b[2]);\n            }\n        });\n\n        // Step 3: Create a result array and fill it with the sorted original nums\n        int[] sortedNums = new int[nums.length];\n        for (int i = 0; i < mappedList.size(); i++) {\n            sortedNums[i] = mappedList.get(i)[0];\n        }\n\n        return sortedNums;\n    }\n}\n```\n```C []\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint compare(const void* a, const void* b) {\n    return (*(*(int**)a + 1) - *(*(int**)b + 1));\n}\n\nint* sortJumbled(int* mapping, int mappingSize, int* nums, int numsSize,\n                 int* returnSize) {\n    int** mapping_nums = malloc(sizeof(int*) * numsSize);\n    for (int i = 0; i < numsSize; i++) {\n        *(mapping_nums + i) = calloc(2, sizeof(int));\n        mapping_nums[i][0] = i;\n        mapping_nums[i][1] = mapping[nums[i] % 10];\n        int power = 10;\n        int new_num = nums[i] / 10;\n        while (new_num > 0) {\n            mapping_nums[i][1] += mapping[new_num % 10] * power;\n            power *= 10;\n            new_num /= 10;\n        }\n    }\n\n    qsort(mapping_nums, numsSize, sizeof(int*), compare);\n    int* ans = malloc(sizeof(int) * numsSize);\n    for (*returnSize = 0; *returnSize < numsSize; (*returnSize)++) {\n        ans[*returnSize] = nums[mapping_nums[*returnSize][0]];\n        free(*(mapping_nums + *returnSize));\n    }\n\n    free(mapping_nums);\n\n    return ans;\n}\n```\n```python []\nclass Solution(object):\n    def sortJumbled(self, mapping, nums):\n        """\n        :type mapping: List[int]\n        :type nums: List[int]\n        :rtype: List[int]\n        """\n        def value(d):\n            if d == 0: return mapping[0]\n            res = 0\n            curr = 1\n            while d:\n                d, r = divmod(d, 10)\n                res += curr * mapping[r]\n                curr *= 10\n            return res\n        nums.sort(key = value)\n        return nums\n```\n\n\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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] sortJumbled(int[] mapping, int[] nums) {\n        // Step 1: Create a list to store original nums and their mapped values\n        List<int[]> mappedList = new ArrayList<>();\n        for (int i = 0; i < nums.length; i++) {\n            String s = Integer.toString(nums[i]);\n            StringBuilder n = new StringBuilder();\n            for (char ch : s.toCharArray()) {\n                n.append(mapping[ch - \'0\']);\n            }\n            mappedList.add(new int[] { nums[i], Integer.parseInt(n.toString()), i });\n        }\n\n        // Step 2: Sort the list based on the mapped values and original indices for\n        // stability\n        mappedList.sort((a, b) -> {\n            if (a[1] != b[1]) {\n                return Integer.compare(a[1], b[1]);\n            } else {\n                return Integer.compare(a[2], b[2]);\n            }\n        });\n\n        // Step 3: Create a result array and fill it with the sorted original nums\n        int[] sortedNums = new int[nums.length];\n        for (int i = 0; i < mappedList.size(); i++) {\n            sortedNums[i] = mappedList.get(i)[0];\n        }\n\n        return sortedNums;\n    }\n}\n```
['Array', 'C', 'Sorting', 'Python', 'C++', 'Java', 'Python3']