1337. Single Number III — Two Elements Appear Once

MediumBit ManipulationBit ManipulationXORPartition

Given an array where exactly two elements appear once and every other element appears exactly twice, return those two elements sorted in ascending order.

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

Output: Return the two unique values as [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":[9,4]}
Output: [4,9]
Explanation: Both appear once -> [4,9] after sorting.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →