2191. Sort the Jumbled Numbers Medium
1/**
2 * [2191] Sort the Jumbled Numbers
3 *
4 * You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.
5 * The mapped value of an integer is the new integer obtained by replacing each occurrence of digit i in the integer with mapping[i] for all 0 <= i <= 9.
6 * You are also given another integer array nums. Return the array nums sorted in non-decreasing order based on the mapped values of its elements.
7 * Notes:
8 *
9 * Elements with the same mapped values should appear in the same relative order as in the input.
10 * The elements of nums should only be sorted based on their mapped values and not be replaced by them.
11 *
12 *
13 * Example 1:
14 *
15 * Input: mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38]
16 * Output: [338,38,991]
17 * Explanation:
18 * Map the number 991 as follows:
19 * 1. mapping[9] = 6, so all occurrences of the digit 9 will become 6.
20 * 2. mapping[1] = 9, so all occurrences of the digit 1 will become 9.
21 * Therefore, the mapped value of 991 is 669.
22 * 338 maps to 007, or 7 after removing the leading zeros.
23 * 38 maps to 07, which is also 7 after removing leading zeros.
24 * Since 338 and 38 share the same mapped value, they should remain in the same relative order, so 338 comes before 38.
25 * Thus, the sorted array is [338,38,991].
26 *
27 * Example 2:
28 *
29 * Input: mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123]
30 * Output: [123,456,789]
31 * Explanation: 789 maps to 789, 456 maps to 456, and 123 maps to 123. Thus, the sorted array is [123,456,789].
32 *
33 *
34 * Constraints:
35 *
36 * mapping.length == 10
37 * 0 <= mapping[i] <= 9
38 * All the values of mapping[i] are unique.
39 * 1 <= nums.length <= 3 * 10^4
40 * 0 <= nums[i] < 10^9
41 *
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/sort-the-jumbled-numbers/
46// discuss: https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51 pub fn sort_jumbled(mapping: Vec<i32>, nums: Vec<i32>) -> Vec<i32> {
52 vec![]
53 }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_2191() {
64 }
65}
66
Back
© 2025 bowen.ge All Rights Reserved.