Sorting an Array Based on Mapped Values in a Shuffled Decimal System
Intuition\nThe task involves sorting an array of integers based on their mapped values, as defined by a given mapping rule. To solve this, we need to compute th
# Intuition\nThe task involves sorting an array of integers based on their mapped values, as defined by a given mapping rule. To solve this, we need to compute the mapped value for each integer in the array and then sort the array based on these mapped values.\n\n# Approach\n1. ********Mapping Calculation:********\n    - For each number in the array nums, compute its mapped value using the mapping array.\n    - Convert each digit of the number to its corresponding mapped value and form the new mapped number.\n\n2. **Pairing Original and Mapped Values:**\n\n    - Store each original number along with its computed mapped value in a list of pairs. This allows us to keep track of the original indices, preserving the relative order of elements with the same mapped value.\n\n3. **Sorting:**\n\n    - Sort the list of pairs based on the mapped values. In the case of a tie (i.e., same mapped value), the original relative order is maintained due to the nature of the sort algorithm used (stable sort).\n\n4. **Reconstruction:**\n    - Extract the original numbers from the sorted list of pairs to form the final sorted array.\n\n# Complexity\n\n- Time complexity: O(nlogn)\n\n- Space complexity: O(n)\n\n Where \'n\' is size of nums array\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> sortJumbled(vector<int>& mapping, vector<int>& nums) {\n        int n = nums.size();\n        vector<pair<int, int>> mp;\n\n        for(int i = 0; i<n;i++){\n\n            int temp = nums[i];\n            int newNum = 0;\n            int tens = 1;\n\n            if(temp==0)\n                newNum = mapping[0];\n\n            while(temp>0){\n                newNum += tens*mapping[temp%10];\n                tens*=10;\n                temp /= 10;\n            }\n\n            mp.push_back({newNum, i});\n        }\n\n        sort(mp.begin(), mp.end());\n\n        vector<int> ans(n);\n        for(int i=0;i<n;i++)\n            ans[i] = nums[mp[i].second];\n        \n        return ans;\n    }\n};\n```
['Array', 'Hash Table', 'Sorting', 'C++']