Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Find the Distance Value Between Two Arrays

XPChallenge Points: 10
levelLevel: Easy

You are given two arrays and a number d.
For every element in arr1, check whether all the elements in arr2 are farther than d away from it.

We count how many elements in arr1 do not have any value in arr2 such that:


|arr1[i]-arr2[j]| ≤ d

Return that count.

Example 1:

Input: arr1 = [5, 2, 12], arr2 = [20], d = 5

Output: 3

Explanation:

All elements are far from 20 by more than 5.

Example 2:

Input: arr1 = [3, 10, 15], arr2 = [8, 9], d = 1

Output: 1

Explanation:

Only 3 is far enough. 10 and 15 are close to elements in arr2.

Example 3:

Input: arr1 = [1, 6, 11], arr2 = [5, 7], d = 1

Output: 1

Explanation:

Only 11 is far enough.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result