P16136 [GeeksforGeeks] Finding the numbers0215
普及
题目描述

Given an array A containing 2N+2 positive numbers, out of which 2N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order.
Example 1:
Input:
N = 2
arr[] = {1, 2, 3, 2, 1, 4}
Output:
3 4
Explanation:
3 and 4 occur exactly once.
Example 2:
Input:
N = 1
arr[] = {2, 1, 3, 2}
Output:
1 3
Explanation:
1 3 occur exactly once.
Your Task:
You do not need to read or print anything. Your task is to complete the function singleNumber() which takes the array as input parameter and returns a list of two numbers which occur exactly once in the array. The list must be in ascending order.
Expected Time Complexity: O(N)
Expected Space Complexity: O(1)
Constraints:
1 <= length of array <= 10^{6 }
1 <= Elements in array <= 5 * 10^{6}

输入格式

见题面

输出格式

见题面

样例输入
N = 2 arr[] = {1, 2, 3, 2, 1, 4}
样例输出
3 4