Simple C++ Solution | C++
IntuitionThe problem requires sorting the array nums based on a transformed version of each number, where each digit is mapped according to mapping. The goal is
### **Intuition**  
The problem requires sorting the array `nums` based on a transformed version of each number, where each digit is mapped according to `mapping`. The goal is to sort based on the mapped values while maintaining the relative order of elements with the same mapped value.  

### **Approach**  
1. **Transform Each Number:**  
   - Convert each number in `nums` to its mapped version using `formnum()`, replacing each digit with `mapping[d]`.  
2. **Group by Mapped Values:**  
   - Use an `unordered_map<int, vector<int>> mp` to store original numbers grouped by their mapped values.  
3. **Sort the Groups by Mapped Values:**  
   - Convert `mp` to a vector of pairs and sort it based on the mapped values.  
4. **Reconstruct the Result:**  
   - Extract elements in sorted order while preserving their relative order for the same mapped values.  

### **Complexity**  
- **Time Complexity:** \( O(n \log n) \)  
  - Mapping each number takes \( O(k) \) (where \( k \) is the number of digits).  
  - Sorting takes \( O(n \log n) \).  
- **Space Complexity:** \( O(n) \)  
  - Extra space is used for the map and result vector.

# Code
```cpp []
class Solution {
public:
    int formnum(int num, vector<int>& mapping) {
        if (num == 0) return mapping[0]; 
        int newNum = 0, place = 1;
        while (num > 0) {
            int d = num % 10;  
            newNum = mapping[d] * place + newNum; 
            place *= 10;
            num /= 10;
        }
        return newNum;
    }


    vector<int> sortJumbled(vector<int>& mapping, vector<int>& nums) {
        unordered_map<int,vector<int>>mp;
        vector<int>ans;
        for(int i=0;i<nums.size();i++){
            int a=formnum(nums[i],mapping);
            mp[a].push_back(nums[i]);
        }
        vector<pair<int,vector<int>>>v(mp.begin(),mp.end());
        sort(v.begin(),v.end());
        for(int i=0;i<v.size();i++){
            for(int j=0;j<v[i].second.size();j++){
                ans.push_back(v[i].second[j]);
            }
        }
        return ans;
    }
};
```
['Ordered Map', 'C++']