Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
1
Indexable
Never
//{ Driver Code Starts
#include<bits/stdc++.h>
using namespace std;

// } Driver Code Ends
class Solution
{
public:
    vector<int> singleNumber(vector<int> arr) 
    {
        vector<int> ans;
        int XOR=arr[0];
        for(int i=0;i<arr.size();i++){
            XOR=XOR ^ arr[i]; //get xor of 2 unique umbers
        }
        int right_bit =XOR & ~(XOR-1);
        int x=0,y=0;
        for(int i=0;i<arr.size();i++){ //seperate 2 nos into x and y based on right most set bit
            if(arr[i]&right_bit){
                x=x^arr[i];
            }else{
                y=y^arr[i];
            }
        }
        ans.push_back(x);
        ans.push_back(y);
        return ans;
    }
};

//{ Driver Code Starts.
int main(){
    int T;
    cin >> T;
    while(T--)
    {
    	int n; 
    	cin >> n;
    	vector<int> v(2 * n + 2);
    	for(int i = 0; i < 2 * n + 2; i++)
    		cin >> v[i];
    	Solution ob;
    	vector<int > ans = ob.singleNumber(v);
    	for(auto i: ans)
    		cout << i << " ";
    	cout << "\n";
    }
	return 0;
}
// } Driver Code Ends