Explained Simply ✨
Intuition\nTo solve this problem, the key is to understand how to map each number based on the given mapping array and then sort the original numbers based on t
# Intuition\nTo solve this problem, the key is to understand how to map each number based on the given `mapping` array and then sort the original numbers based on these mapped values. The challenge is to maintain the relative order of the original numbers when their mapped values are equal.\n\n# Approach\n1. **Mapping the Numbers**: \n   - For each number in the `nums` array, convert each digit of the number using the `mapping` array to get the mapped value.\n   - Store these mapped values in a temporary array `temp`.\n   \n2. **Sorting with Indices**: \n   - Create an array of indices that corresponds to the original `nums` array.\n   - Sort this array of indices based on the mapped values stored in `temp`. If two mapped values are the same, maintain the relative order of their indices.\n   \n3. **Generating the Result**:\n   - Use the sorted indices to construct the final sorted array of the original numbers.\n\n# Complexity\n- Time complexity:\n  The time complexity is \\(O(n \\log n)\\), where \\(n\\) is the number of elements in the `nums` array. This is primarily due to the sorting step.\n\n- Space complexity:\n  The space complexity is \\(O(n)\\), as we use additional space for the temporary array `temp` and the array of indices.\n\n\n# Code\n```\nclass Solution {\n    public int[] sortJumbled(int[] mapping, int[] nums) {\n        int temp[] = new int[nums.length];\n        for(int i=0;i<nums.length;i++){\n            int n = nums[i];\n            int k=1;\n            int ans = 0;\n            if(n==0){\n                temp[i]=mapping[0];\n                continue;\n            }\n            while(n>0){\n                ans += mapping[n%10]*k;\n                n/=10;\n                k*=10;\n            }\n            temp[i]=ans;\n        }\n        Integer[] index = new Integer[nums.length];\n        for(int i=0;i<nums.length;i++) index[i] = i;\n        Arrays.sort(index, (i1, i2) ->{\n            if(temp[i1] != temp[i2]){\n                return temp[i1] - temp[i2];\n            }\n            else return i1 - i2;\n        });\n\n        for(int i=0;i<nums.length;i++){\n            temp[i] = nums[index[i]];\n        }\n        return temp;\n    }\n}\n```
['Java']