3761. Minimum Absolute Distance Between Mirror Pairs Medium

@problem@discussion
#Array#Hash Table#Math



1/**
2 * [3761] Minimum Absolute Distance Between Mirror Pairs
3 *
4 * You are given an integer array nums.
5 * A mirror pair is a pair of indices (i, j) such that:
6 * 
7 * 	0 <= i < j < nums.length, and
8 * 	reverse(nums[i]) == nums[j], where reverse(x) denotes the integer formed by reversing the digits of x. Leading zeros are omitted after reversing, for example reverse(120) = 21.
9 * 
10 * Return the minimum absolute distance between the indices of any mirror pair. The absolute distance between indices i and j is abs(i - j).
11 * If no mirror pair exists, return -1.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [12,21,45,33,54]</span>
16 * Output: <span class="example-io">1</span>
17 * Explanation:
18 * The mirror pairs are:
19 * 
20 * 	(0, 1) since reverse(nums[0]) = reverse(12) = 21 = nums[1], giving an absolute distance abs(0 - 1) = 1.
21 * 	(2, 4) since reverse(nums[2]) = reverse(45) = 54 = nums[4], giving an absolute distance abs(2 - 4) = 2.
22 * 
23 * The minimum absolute distance among all pairs is 1.
24 * </div>
25 * <strong class="example">Example 2:
26 * <div class="example-block">
27 * Input: <span class="example-io">nums = [120,21]</span>
28 * Output: <span class="example-io">1</span>
29 * Explanation:
30 * There is only one mirror pair (0, 1) since reverse(nums[0]) = reverse(120) = 21 = nums[1].
31 * The minimum absolute distance is 1.
32 * </div>
33 * <strong class="example">Example 3:
34 * <div class="example-block">
35 * Input: <span class="example-io">nums = [21,120]</span>
36 * Output: <span class="example-io">-1</span>
37 * Explanation:
38 * There are no mirror pairs in the array.
39 * </div>
40 *  
41 * Constraints:
42 * 
43 * 	1 <= nums.length <= 10^5
44 * 	1 <= nums[i] <= 10^9​​​​​​​
45 * 
46 */
47pub struct Solution {}
48
49// problem: https://leetcode.com/problems/minimum-absolute-distance-between-mirror-pairs/
50// discuss: https://leetcode.com/problems/minimum-absolute-distance-between-mirror-pairs/discuss/?currentPage=1&orderBy=most_votes&query=
51
52// submission codes start here
53
54impl Solution {
55    pub fn min_mirror_pair_distance(nums: Vec<i32>) -> i32 {
56        0
57    }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn test_3761() {
68    }
69}
70

Back
© 2026 bowen.ge All Rights Reserved.