Leetcode Problem 1385. Find the Distance Value Between Two Arrays

1385. Find the Distance Value Between Two Arrays

Leetcode Solutions

Brute Force Approach

  1. Initialize a counter result to 0.
  2. Loop through each element arr1[i] in arr1.
  3. For each arr1[i], loop through each element arr2[j] in arr2.
  4. Check if the absolute difference |arr1[i] - arr2[j]| is less than or equal to d.
  5. If such an element is found, break the inner loop as the condition is not satisfied.
  6. If the inner loop completes without breaking, increment result by 1.
  7. Return the value of result after all iterations are complete.
UML Thumbnail

Sorting and Binary Search Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...