1385. Find the Distance Value Between Two Arrays

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1385

class Solution:
    def findTheDistanceValue(self, arr1: List[int], arr2: List[int], d: int) -> int:
        def check(a: int) -> bool:
            i = bisect_left(arr2, a - d)
            return i == len(arr2) or arr2[i] > a + d

        arr2.sort()
        return sum(check(a) for a in arr1)