LC 1385. Find the Distance Value Between Two Arrays

Nilanjan Deb · April 5, 2020

This is my CPP solution.

class Solution {
public:
    int findTheDistanceValue(vector<int>& arr1, vector<int>& arr2, int d) {
        int n = arr1.size(),m = arr2.size(),cnt=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(abs(arr1[i]-arr2[j])<=d){
                    cnt++;
                    break;
                }
            }
        }
        return n-cnt;
    }
};


Dicussion Forum