---
# System prepended metadata

title: 2191. Sort the Jumbled Numbers
tags: [Leetcode, Sorting, Medium]

---

# 2191. Sort the Jumbled Numbers
###### tags: `Leetcode` `Medium` `Sorting`
Link: https://leetcode.com/problems/sort-the-jumbled-numbers/description/
## Code
```java=
class Solution {
    public int[] sortJumbled(int[] mapping, int[] nums) {
        int n = nums.length;
        Integer[] indices = new Integer[n];
        for(int i=0; i<nums.length; i++) indices[i] = i;
        Arrays.sort(indices, (a,b)->(convert(nums[a], mapping)-convert(nums[b], mapping)));
        int[] ans = new int[n];
        for(int i=0; i<nums.length; i++){
            ans[i] = nums[indices[i]];
        }
        return ans;
    }
    public int convert(int a, int[] mapping){
        if(a==0) return mapping[0];
        int n = 0, f = 1;
        while(a!=0){
            n += f*mapping[a%10];
            f *= 10;
            a /= 10;
        }
        return n;
    }
}
```