<p>You are given a <strong>0-indexed</strong> integer array <code>mapping</code> which represents the mapping rule of a shuffled decimal system. <code>mapping[i] = j</code> means digit <code>i</code> should be mapped to digit <code>j</code> in this system.</p>

<p>The <strong>mapped value</strong> of an integer is the new integer obtained by replacing each occurrence of digit <code>i</code> in the integer with <code>mapping[i]</code> for all <code>0 &lt;= i &lt;= 9</code>.</p>

<p>You are also given another integer array <code>nums</code>. Return <em>the array </em><code>nums</code><em> sorted in <strong>non-decreasing</strong> order based on the <strong>mapped values</strong> of its elements.</em></p>

<p><strong>Notes:</strong></p>

<ul>
	<li>Elements with the same mapped values should appear in the <strong>same relative order</strong> as in the input.</li>
	<li>The elements of <code>nums</code> should only be sorted based on their mapped values and <strong>not be replaced</strong> by them.</li>
</ul>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38]
<strong>Output:</strong> [338,38,991]
<strong>Explanation:</strong> 
Map the number 991 as follows:
1. mapping[9] = 6, so all occurrences of the digit 9 will become 6.
2. mapping[1] = 9, so all occurrences of the digit 1 will become 9.
Therefore, the mapped value of 991 is 669.
338 maps to 007, or 7 after removing the leading zeros.
38 maps to 07, which is also 7 after removing leading zeros.
Since 338 and 38 share the same mapped value, they should remain in the same relative order, so 338 comes before 38.
Thus, the sorted array is [338,38,991].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123]
<strong>Output:</strong> [123,456,789]
<strong>Explanation:</strong> 789 maps to 789, 456 maps to 456, and 123 maps to 123. Thus, the sorted array is [123,456,789].
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>mapping.length == 10</code></li>
	<li><code>0 &lt;= mapping[i] &lt;= 9</code></li>
	<li>All the values of <code>mapping[i]</code> are <strong>unique</strong>.</li>
	<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
	<li><code>0 &lt;= nums[i] &lt; 10<sup>9</sup></code></li>
</ul>

"""
mapping[i] = j means digit i should be mapped to digit j
0 -> 8
1 -> 9
2 -> 4
3 -> 0
4 -> 2

9 -> 6

991 -> 669
mapping[9] mapping[9] mapping[1]
mapped_value = new integer obtained by replacing each occurence of digit i with mapping[i]

etc...

Return nums sorted in non-decreasign order based on mapped values of its elements
338 -> 007

338 % 10 -> 8 // 1 -> 8 -> 7
330 % 100 -> 30 // 10 -> 3 -> 0
300 % 1000 -> 300 // 100 -> 3 -> 0
while place < original number: 

0 -> successfully deleted everything 

Convert this num a string first 338 -> "338"
res = ["0", "0", "7"] -> list of strings
Iterate through the string of "338":
    - Get the current digit (from front to back)
    - Convert the digit to a number from mapping -> str(mapping[int(i)])

int("007")

38 -> 07
Stable Sort Algorithm



Iterate through all of nums 
    Convert each num to their mapping num
    Sort based on the new mapping num


get_mapped_value: O(1) -> assume a max fixed number of digits in number 
    -> Convert a number to a mapped number given mapping

nums.sort(key = lambda x: get_mapped_value(x)) STABLE O(n log n)
"""
class Solution:
    def get_mapped_value(self, num, mapping):
        """
        991 
        place = 1000
        progress = 991 - 1 = 990 - 90 = 0
        value = 9 + 60 + 600 = 669

        current = 900 % 1000 -> 900 // 100 -> 9


        """
        if num == 0: return mapping[num]
        place = 1
        progress = num
        mapped_value = 0
        while progress > 0:
            current = progress % (place * 10)
            progress -= current
            current = current // place
            mapped_value += (mapping[current] * place)
            place *= 10
        return mapped_value


    def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
        nums.sort(key = lambda num : self.get_mapped_value(num, mapping)) # O(n log n)
        return nums
843