Find the Distance Value Between Two Arrays

Try to solve the Find the Distance Value Between Two Arrays problem.

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 in arr2 such that arr1[i]arr2[j]<=|arr1[i]-arr2[j]| <= d.

Constraints:

  • 1<=1 <= arr1.length, arr2.length <=500 <= 500

  • 1000<=-1000 <= arr1[i], arr2[j] <=1000<= 1000

  • 0<=0 <= d <=100<= 100

Examples

Press + to interact
canvasAnimation-image
1 of 3

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

1

Given arr1 = [3, 7, 9], arr2 = [4, 8, 10], and d = 1, what is the distance value between the two arrays?

A)

0

B)

1

C)

2

D)

3

Question 1 of 40 attempted

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.

Drag and drop the cards to rearrange them in the correct sequence.

Press + to interact
Java
usercode > Solution.java
public class Solution
{
public static int findTheDistanceValue(int[] arr1, int[] arr2, int d)
{
// Replace this placeholder return statement with your code
return -1;
}
}
Find the Distance Value Between Two Arrays

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.