Back to November Back to Year 2026
EASY 05 Nov 2026 View on LeetCode

1385. Find the Distance Value Between Two Arrays

</> Solution

/**
 * Problem: LeetCode 1385 - Find the Distance Value Between Two Arrays
 * Difficulty: Easy
 * Language: Java
 * Author: CodeByTushu
 */
class Solution {
    public int findTheDistanceValue(int[] arr1, int[] arr2, int d) {
        int count = 0;

        for (int a : arr1) {
            boolean ok = true;
            for (int b : arr2) {
                if (Math.abs(a - b) <= d) {
                    ok = false;
                    break;
                }
            }
            if (ok) count++;
        }

        return count;
    }
}

TIME COMPLEXITY

O(n)

SPACE COMPLEXITY

O(1)

TOPICS

Array Binary Search Sorting Two Pointers