✅: [C++] | Easy Code | Min-heap | Without Sorting | Detailed
The solution is quite obvious and simple.\n1. make a min heap of pair (min heap so that you can have sorted answer).\n2. use a function to calculate the resulta
The solution is quite obvious and simple.\n1. make a min heap of pair (min heap so that you can have sorted answer).\n2. use a function to calculate the resultant value acc to map\n3. Push the calculated value along with indexes **(yes! to track the order)**\n4. pop and insert to result vector\n5. Get AC and sleep, LOL\n\n```\nclass Solution {\npublic:\n    \n    int calculate(int n, vector<int> m) {\n        int x = 1;\n        int ans = 0;\n        if(n == 0) {       // very imp condition\n            return m[0];\n        }\n        while(n!=0) {\n            int d = n%10;\n            n/=10;\n            ans += (x*m[d]);\n            x*=10;\n            \n        }\n        \n        return ans;\n    }\n    \n    vector<int> sortJumbled(vector<int>& mapping, vector<int>& nums) {\n        vector<int> ans;\n        priority_queue <pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq;\n        for(int i =0;i<nums.size();i++) {\n            int x = calculate(nums[i], mapping);\n            pq.push({x,i});\n        }\n        \n        \n        while(!pq.empty()) {\n            auto x = pq.top();\n            pq.pop();\n            ans.push_back(nums[x.second]);\n        }\n        \n        return ans;\n    }\n};\n```\n\nComment your doubts for clarification.\n
['C', 'Heap (Priority Queue)', 'Java']