Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays.

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]| &lt;= d.

&nbsp;
Example 1:

Input: arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2
Output: 2
Explanation: 
For arr1[0]=4 we have: 
|4-10|=6 &gt; d=2 
|4-9|=5 &gt; d=2 
|4-1|=3 &gt; d=2 
|4-8|=4 &gt; d=2 
For arr1[1]=5 we have: 
|5-10|=5 &gt; d=2 
|5-9|=4 &gt; d=2 
|5-1|=4 &gt; d=2 
|5-8|=3 &gt; d=2
For arr1[2]=8 we have:
|8-10|=2 &lt;= d=2
|8-9|=1 &lt;= d=2
|8-1|=7 &gt; d=2
|8-8|=0 &lt;= d=2


Example 2:

Input: arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3
Output: 2


Example 3:

Input: arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6
Output: 1


&nbsp;
Constraints:


	1 &lt;= arr1.length, arr2.length &lt;= 500
	-1000 &lt;= arr1[i], arr2[j] &lt;= 1000
	0 &lt;= d &lt;= 100


class Solution:
	def findTheDistanceValue(self, array1: List[int], array2: List[int], d: int) -> int:

		result = 0

		array2 = sorted(array2)

		for num in array1:

			flag = True

			low = 0
			high = len(array2)-1

			while low <= high:

				mid = (low + high) // 2

				if abs(array2[mid] - num) <= d:
					flag = False
					break

				elif array2[mid] > num:
					high = mid - 1

				else:
					low = mid + 1;

			if flag == True:

				result = result + 1

		return result
class Solution {
    public int findTheDistanceValue(int[] arr1, int[] arr2, int d) {
        int x=0,val=0;
        for(int i:arr1){
            for(int j:arr2){
                if(Math.abs(i-j)<=d){
                   x--;
                    break;
                }
            }
            x++;
        }
      return x;
    }
}
class Solution {
public:
    int findTheDistanceValue(vector<int>& arr1, vector<int>& arr2, int d) {
        sort(arr2.begin(),arr2.end());
        int ans = 0;
        for(int i : arr1){
            int id = lower_bound(arr2.begin(),arr2.end(),i) - arr2.begin();
            int closest = d+1;
            if(id != arr2.size()){
                closest = min(abs(arr2[id]-i), closest);
            } 
            if(id != 0){
                closest = min(abs(arr2[id-1]-i), closest);
            }
            if(closest > d) ans++;
        }
        return ans;
    }
};
/**
 * @param {number[]} arr1
 * @param {number[]} arr2
 * @param {number} d
 * @return {number}
 */
var findTheDistanceValue = function(arr1, arr2, d) {
    const arr2Sorted = arr2.sort((a, b) => a - b);
    let dist = 0;

    for (const num of arr1) {
        if (isDistanceValid(num, d, arr2Sorted)) {
            dist += 1;
        }
    }

    return dist;
};

function isDistanceValid(number, dist, array) {
    let left = 0;
    let right = array.length - 1;

    while (left <= right) {
        const mid = Math.floor((right + left) / 2);

        if (Math.abs(number - array[mid]) <= dist) {
            return false;
        }

        if (array[mid] < number) {
            left = mid + 1;
        }

        if (array[mid] > number) {
            right = mid - 1;
        }
    }

    return true;
}
Find the Distance Value Between Two Arrays