C++ Solution - Beats 99%
Intuition\n Describe your first thoughts on how to solve this problem. \n- have a method to convert a given number into its mapped form for each digit, can do t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- have a method to convert a given number into its mapped form for each digit, can do this using a recursive function, where the basecase would just return 0, but a special case should be considered for if nums[i] == 0\n- sort an vector of pairs, the first element beging the mapped element, and the second being the index of that number in nums, since we want to maintain original order if they have the same mapped value, the index will retain order\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- go through each number, and create its proper mapping by using the recursive function and taking into account the special case of nums[i] == 0\n- use the sort function on the vector of pairs {mappedNum, index}\n- use a new array, and reconstruct the array by iterating through and using the mapped index to reference the correct number from nums\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n*k + nlogn)$$ - n is length of nums, k is the number of digits in a number\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n * k)$$ - n for auxiliary arrays and n*k for recursive call stack over each element\n\n# Code\n```\nclass Solution {\npublic:\n    int makeNum(int n, vector<int> & mapping) {\n        if (n == 0) return 0;\n        return (mapping[n % 10]) + makeNum(n / 10, mapping) * 10;\n    }\n    vector<int> sortJumbled(vector<int>& mapping, vector<int>& nums) {\n        vector<int> ans;\n        vector<pair<int, int>> vec;\n\n        for (int i = 0; i < nums.size(); i++) {\n            if (nums[i] == 0) {\n                vec.push_back({mapping[nums[i]], i});\n            } else {\n                vec.push_back({makeNum(nums[i], mapping), i});\n            }\n        }\n\n        sort(vec.begin(), vec.end());\n\n        for (const auto & [num, i] : vec) {\n            ans.push_back(nums[i]);\n        }\n        return ans;\n    }\n};\n```
['Array', 'Sorting', 'C++']