Skip to content

Commit 1ea1ec4

Browse files
authored
Merge pull request #17 from Sam-bhav-20/main
Issue resolved of finding that arrays are disjoint or not
2 parents 184d97f + 234a669 commit 1ea1ec4

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"iostream": "cpp"
4+
}
5+
}

findDisjoint/disjointOrNot.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define int long long
4+
#define MOD 1000000007
5+
const long long N = 10000005;
6+
7+
main()
8+
{
9+
// Provide the size of array 1 and array 2 with their elements
10+
int n, m;
11+
cout << "Size of first array: ";
12+
cin >> n;
13+
cout << "Size of Second array: ";
14+
cin >> m;
15+
16+
// Initializing arrays
17+
int a[n], b[m];
18+
19+
// Initializing sets for both arrays and a third set to combine them
20+
unordered_set<int> setA, setB, setC;
21+
cout << "Elements of first array: ";
22+
for (int i = 0; i < n; i++)
23+
{
24+
cin >> a[i];
25+
setA.insert(a[i]);
26+
setC.insert(a[i]);
27+
}
28+
cout << "Elements of second array: ";
29+
for (int i = 0; i < m; i++)
30+
{
31+
cin >> b[i];
32+
setB.insert(b[i]);
33+
setC.insert(b[i]);
34+
}
35+
36+
// Comparing the sizes of sets to determine if they are disjoint
37+
int sizeA = setA.size();
38+
int sizeB = setB.size();
39+
int sizeC = setC.size();
40+
41+
if (sizeA + sizeB == sizeC)
42+
{
43+
cout << "Yes, the arrays are disjoint" << endl;
44+
}
45+
46+
else
47+
{
48+
cout << "Arrays are not disjoint , they have some common values" << endl;
49+
}
50+
51+
return 0;
52+
}

0 commit comments

Comments
 (0)