-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathE0104.cpp
More file actions
39 lines (32 loc) · 706 Bytes
/
E0104.cpp
File metadata and controls
39 lines (32 loc) · 706 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
/*
Problem Statement: https://www.hackerrank.com/challenges/beautiful-pairs/problem
*/
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
int beautifulPairs(vector<int> &A, vector<int> &B) {
int n, common;
unordered_map<int, int> cntA, cntB;
common = 0;
n = A.size();
for (int i = 0; i < n; i++) {
cntA[A[i]]++;
cntB[B[i]]++;
}
for (auto cnt: cntA)
common += min(cnt.second, cntB[cnt.first]);
return (common == n) ? common - 1 : common + 1;
}
int main() {
int n;
cin >> n;
vector<int> A(n), B(n);
for (int i = 0; i < n; i++)
cin >> A[i];
for (int i = 0; i < n; i++)
cin >> B[i];
cout << beautifulPairs(A, B);
return 0;
}