Two numbers with odd occurrences
Submissions: 1864   Accuracy:


  Difficulty: Easy   Marks: 2

Given an unsorted array arr[] of size N and that contains even number of occurrences for all numbers except two numbers. Find the two numbers in decreasing order which have odd occurrences.

Note: Expected O(n) time complexity and O(1) extra space.

The 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. 

Print two space separated integers which have odd occurrences. Print the greater number first and then the smaller odd number.

1 <= T <= 100
2 <= N <= 105
1 <= arr[i] <= 105

4 2 4 5 2 3 3 1
1 7 5 5 4 4

5 1
7 1

Testcase 1: 5 and 1 are odd occurring elements in the array.
Testcase 2: 7 and 1 are odd occurring elements in the array.


** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ayush Govil
Author: Ayush Govil 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.