1307. Find the Two Non-Repeating Elements

EasyBit ManipulationBit ManipulationXORArray

Given an array where every element appears exactly twice except two elements that each appear once, return those two elements in ascending order. Use XOR and a distinguishing bit to separate them.

Input: A JSON object {"nums": [<integers>]} with exactly two values appearing once.

Output: Return the two unique values as an array [min, max].

Examples

Example 1
Input: {"nums":[1,2,1,3,2,5]}
Output: [3,5]
Explanation: The two singles are 3 and 5 -> [3,5].
Example 2
Input: {"nums":[4,6]}
Output: [4,6]
Explanation: Both appear once -> [4,6].

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →