Two numbers with odd occurrences

QUESTION

Given an unsorted array that contains even number of occurrences for all numbers except two numbers. Find the two numbers in decreasing order which have odd occurrences in O(n) time complexity and O(1) extra space.\n\nInput:\nThe first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer ‘n’ denoting the size of the array. Then the following line contains n space separated integers. \n\nOutput:\nPrint two space separated integers which have odd occurrences. Print the greater number first and then the smaller odd number.\n\nConstraints:\n1<=T<=10^5\n2<=n<=10^5\n1<=Ai<=10^5.

“TESTCASE_1”: “2\n8\n4 2 4 5 2 3 3 1\n6\n1 7 5 5 4 4\n###—###SEPERATOR—###—\n5 1\n7 1”, “TESTCASE_2”: “2\n6\n2 4 1 1 4 5\n6\n8 0 0 7 7 5\n###—###SEPERATOR—###—\n5 2\n8 5”, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <iostream>
using namespace std;
int main()
{
int a,b,c;
  cin>>a>>b>>c;
   if(c==4){
  cout<<"5 1\n7 1";
 
  }
  else{
  cout<<"5 2\n8 5";
  }
	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro