Find Two Non-Repeating Elements Problem Statement

Given an array of integers ARR with size N, where exactly two elements appear only once and all others appear exactly twice, identify and return the two unique elements.

Input:

The first input line contains an integer N, the size of the array.
The second input line contains N space-separated integers representing the elements of the array.

Output:

Output two space-separated integers that appear only once, ensuring the first integer is smaller than the second.

Example:

Input:
N = 6
ARR = [2, 4, 6, 8, 4, 2]
Output:
6 8

Constraints:

  • 2 <= N <= 10^5
  • -10^5 <= ARR[i] <= 10^5
Note:
1. There will always be only two integers that appear exactly once, while the rest appear twice.
2. Aim to solve this problem in linear time and with constant space.
AnswerBot
4mo

Given an array where all elements appear twice except two, find and return the two unique elements.

  • Use XOR operation to find the XOR of all elements in the array, which will give the XOR of the two un...read more

Help your peers!
Select
Add answer anonymously...
TO THE NEW Technical Trainee Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits