Find the Distance Value Between Two Arrays
Try to solve the Find the Distance Value Between Two Arrays problem.
We'll cover the following
Statement
You are given two integer arrays, arr1
and arr2
, along with an integer d
. Your task is to find and return the distance value between these arrays.
Note: The distance value is defined as the count of elements in
arr1
for which there is no element inarr2
such thatd
.
Constraints:
arr1.length
,arr2.length
arr1[i]
,arr2[j]
d
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Find the Distance Value Between Two Arrays
Given arr1
= [3, 7, 9], arr2
= [4, 8, 10], and d
= 1, what is the distance value between the two arrays?
0
1
2
3
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding on how to solve this problem.
public class Solution{public static int findTheDistanceValue(int[] arr1, int[] arr2, int d){// Replace this placeholder return statement with your codereturn -1;}}
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.