-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwo_Repeated_Elements.cpp
More file actions
53 lines (39 loc) · 992 Bytes
/
Two_Repeated_Elements.cpp
File metadata and controls
53 lines (39 loc) · 992 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//{ Driver Code Starts
// Initial template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// User function template for C++
class Solution {
public:
// Function to find two repeated elements.
vector<int> twoRepeated(int n, int arr[]) {
map<int, int>mpp;
int prev = 0;
vector<int> ans;
for(int i = 0; i < n+2; i++)
{
mpp[arr[i]]++;
if(mpp[arr[i]] > 1)
ans.push_back(arr[i]);
}
return ans;
}
};
//{ Driver Code Starts.
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
int arr[n + 2];
for (int i = 0; i < n + 2; i++)
cin >> arr[i];
Solution obj;
vector<int> res;
res = obj.twoRepeated(n, arr);
cout << res[0] << " " << res[1] << endl;
}
return 0;
}
// } Driver Code Ends