Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //{ Driver Code Starts
- #include <bits/stdc++.h>
- using namespace std;
- // } Driver Code Ends
- class Solution{
- public:
- vector<int> findTwoElement(vector<int> arr, int n) {
- // code here
- int ans=-1,ans1=-1;
- int a[n+1]={0};
- for(int i=0;i<arr.size();i++)
- {
- a[arr[i]]+=1;
- }
- for(int i=1;i<=n;i++)
- {
- if(a[i]==0)
- {
- if(ans!=-1)
- {
- continue;
- }
- ans=i;
- }
- if(a[i]==2)
- {
- if(ans1!=-1)
- {
- continue;
- }
- ans1=i;
- }
- if(ans!=-1 && ans1!=-1)
- {
- break;
- }
- }
- return {ans1,ans};
- }
- };
- //{ Driver Code Starts.
- int main() {
- int t;
- cin >> t;
- while (t--) {
- int n;
- cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- Solution ob;
- auto ans = ob.findTwoElement(a, n);
- cout << ans[0] << " " << ans[1] << "\n";
- }
- return 0;
- }
- // } Driver Code Ends
Advertisement
Add Comment
Please, Sign In to add comment