Chef and Dolls
Practice this coding question on Coding Gurukul.
Problem statement
A toy workshop packs dolls in matching pairs identified by an integer type. One doll has lost its partner, and the packing clerk needs its type before sealing the shipment. Your task For each shipment, find the type that occurs an odd number of times. Exactly one type has odd frequency; every other type occurs an even number of times. Important details Process shipments independently. Types need not be consecutive or sorted, and a type may appear more than twice. Use O(n) time and O(1) auxiliary space, for example by combining the identifiers with bitwise XOR. Return the identifier, not its position or frequency. Worked example For types 4, 7, 4, 9, 9, the two 4s and two 9s pair off. Type 7 remains, so print 7.
Input format
The first line contains t. Each test case contains n, followed by n integer types.
Output format
Print one unpaired type per test case.
Constraints
1 <= t <= 100; 1 <= n <= 100001, n is odd; 1 <= type <= 1000000000; sum of n <= 200000.
Sample input
1 5 4 7 4 9 9
Sample output
7
Sign in to run or submit a solution in C++, Java or Python.