C++ easy || images with detailed explaination || using multimap and map
Approach --\n1) First of all we will extract the digits of the given nums and then map that digit with mapping array\n2) Then we have to store that number in so
**Approach --**\n1) First of all we will **extract the digits** of the given nums and then map that digit with **mapping array**\n2) Then we have to store that number in sorted order, but keep in mind if the digits after mapping is same we have to give priority to the original order.\n3) we can do that using multimaps or using map with vector as their frequency (map<int, vector<int> mp)\n-----\n\n**See attached image and code of both the ways below**\n![image](https://assets.leetcode.com/users/images/4b48ff0f-a399-4860-b7ff-d248336bc4f2_1646707690.6806686.jpeg)\n\n**Code using multimap**\n```\nclass Solution {\npublic:\n    vector<int> sortJumbled(vector<int>& mapping, vector<int>& nums) {\n        vector<int> ans;\n        multimap<int, int> mp;\n        \n        for(int i = 0; i < nums.size(); i++) {\n            int power = 1;\n            int number = 0;\n            int n = nums[i];\n            \n            if(n == 0) {\n                mp.insert({mapping[n], n});\n            }\n            \n            else {\n                while(n > 0) {\n                    int digit = n % 10;\n                    int mapped_digit = mapping[digit];\n                    number += mapped_digit * power;\n                    power *= 10;\n                    n = n / 10;\n                }\n                mp.insert({number, nums[i]});\n            }\n        }\n        \n        for(auto it : mp) {\n            ans.push_back(it.second);\n        }\n        return ans;\n    }\n};\n```\n\n**code using map**\n```\nclass Solution {\npublic:\n    vector<int> sortJumbled(vector<int>& mapping, vector<int>& nums) {\n        vector<int> ans;\n        map<int, vector<int>> mp;\n        \n        for(int i = 0; i < nums.size(); i++) {\n            int power = 1;\n            int number = 0;\n            int n = nums[i];\n            \n            if(n == 0) {\n                mp[mapping[n]].push_back(n);\n            }\n            \n            else {\n                while(n > 0) {\n                    int digit = n % 10;\n                    int mapped_digit = mapping[digit];\n                    number += mapped_digit * power;\n                    power *= 10;\n                    n = n / 10;\n                }\n                mp[number].push_back(nums[i]);\n            }\n        }\n        \n        for(auto it : mp) {\n            for(auto x : it.second) {\n                ans.push_back(x);\n            }\n        }\n        return ans;\n    }\n};\n```\n
['C', 'Sorting', 'C++']