java.lang.Object
g2101_2200.s2191_sort_the_jumbled_numbers.Solution

public class Solution extends Object
2191 - Sort the Jumbled Numbers.<p>Medium</p> <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 <= i <= 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><strong>Example 1:</strong></p> <p><strong>Input:</strong> mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38]</p> <p><strong>Output:</strong> [338,38,991]</p> <p><strong>Explanation:</strong></p> <p>Map the number 991 as follows:</p> <ol> <li> <p>mapping[9] = 6, so all occurrences of the digit 9 will become 6.</p> </li> <li> <p>mapping[1] = 9, so all occurrences of the digit 1 will become 9.</p> </li> </ol> <p>Therefore, the mapped value of 991 is 669.</p> <p>338 maps to 007, or 7 after removing the leading zeros.</p> <p>38 maps to 07, which is also 7 after removing leading zeros.</p> <p>Since 338 and 38 share the same mapped value, they should remain in the same relative order, so 338 comes before 38.</p> <p>Thus, the sorted array is [338,38,991].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123]</p> <p><strong>Output:</strong> [123,456,789]</p> <p><strong>Explanation:</strong> 789 maps to 789, 456 maps to 456, and 123 maps to 123. Thus, the sorted array is [123,456,789].</p> <p><strong>Constraints:</strong></p> <ul> <li><code>mapping.length == 10</code></li> <li><code>0 <= mapping[i] <= 9</code></li> <li>All the values of <code>mapping[i]</code> are <strong>unique</strong>.</li> <li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li> <li><code>0 <= nums[i] < 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • sortJumbled

      public int[] sortJumbled(int[] mapping, int[] nums)