1385. Find the Distance Value Between Two Arrays Easy

@problem@discussion
#Array#Two Pointers#Binary Search#Sorting



1/**
2 * [1385] Find the Distance Value Between Two Arrays
3 *
4 * Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays.
5 * The distance value is defined as the number of elements arr1[i] such that there is not any element arr2[j] where |arr1[i]-arr2[j]| <= d.
6 *  
7 * Example 1:
8 * 
9 * Input: arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2
10 * Output: 2
11 * Explanation: 
12 * For arr1[0]=4 we have: 
13 * |4-10|=6 > d=2 
14 * |4-9|=5 > d=2 
15 * |4-1|=3 > d=2 
16 * |4-8|=4 > d=2 
17 * For arr1[1]=5 we have: 
18 * |5-10|=5 > d=2 
19 * |5-9|=4 > d=2 
20 * |5-1|=4 > d=2 
21 * |5-8|=3 > d=2
22 * For arr1[2]=8 we have:
23 * |8-10|=2 <= d=2
24 * |8-9|=1 <= d=2
25 * |8-1|=7 > d=2
26 * |8-8|=0 <= d=2
27 * 
28 * Example 2:
29 * 
30 * Input: arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3
31 * Output: 2
32 * 
33 * Example 3:
34 * 
35 * Input: arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6
36 * Output: 1
37 * 
38 *  
39 * Constraints:
40 * 
41 * 	1 <= arr1.length, arr2.length <= 500
42 * 	-1000 <= arr1[i], arr2[j] <= 1000
43 * 	0 <= d <= 100
44 * 
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/find-the-distance-value-between-two-arrays/
49// discuss: https://leetcode.com/problems/find-the-distance-value-between-two-arrays/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54    pub fn find_the_distance_value(arr1: Vec<i32>, arr2: Vec<i32>, d: i32) -> i32 {
55        0
56    }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_1385() {
67    }
68}
69


Back
© 2025 bowen.ge All Rights Reserved.