forked from Shruti-codes/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistance.cpp
More file actions
39 lines (35 loc) · 939 Bytes
/
distance.cpp
File metadata and controls
39 lines (35 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<math.h>
#include<iostream>
#include<vector>
using namespace std;
int findTheDistanceValue(vector<int>& arr1, vector<int>& arr2, int d)
{
int l1 = arr1.size();
int l2 = arr2.size();
int co=0, flag =0;
for(int i=0; i<l1; i++)
{
for(int j=0; j<l2; j++)
{
if(abs(arr1[i] - arr2[j]) <= d)
{
flag = 1;
break;
}
}
if(flag == 0)
co++;
else
flag = 0;
}
return (co);
}
int main()
{
int arr1[] ={4,5,8};
int arr2[] = {10,9,1,8};
vector<int> v1 (arr1, arr1 + sizeof(arr1) / sizeof(arr1[0]) );
vector<int> v2 (arr2, arr2 + sizeof(arr2) / sizeof(arr2[0]) );
cout<<findTheDistanceValue(v1, v2, 2)<<endl;
return 0;
}