1122. Relative Sort Array Easy

@problem@discussion
#Array#Hash Table#Sorting#Counting Sort



1/**
2 * [1122] Relative Sort Array
3 *
4 * Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.
5 * Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Elements that do not appear in arr2 should be placed at the end of arr1 in ascending order.
6 *  
7 * Example 1:
8 * 
9 * Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]
10 * Output: [2,2,2,1,4,3,3,9,6,7,19]
11 * 
12 * Example 2:
13 * 
14 * Input: arr1 = [28,6,22,8,44,17], arr2 = [22,28,8,6]
15 * Output: [22,28,8,6,17,44]
16 * 
17 *  
18 * Constraints:
19 * 
20 * 	1 <= arr1.length, arr2.length <= 1000
21 * 	0 <= arr1[i], arr2[i] <= 1000
22 * 	All the elements of arr2 are distinct.
23 * 	Each arr2[i] is in arr1.
24 * 
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/relative-sort-array/
29// discuss: https://leetcode.com/problems/relative-sort-array/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34    pub fn relative_sort_array(arr1: Vec<i32>, arr2: Vec<i32>) -> Vec<i32> {
35        vec![]
36    }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_1122() {
47    }
48}
49


Back
© 2025 bowen.ge All Rights Reserved.