File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "files.associations" : {
3+ "iostream" : " cpp"
4+ }
5+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments