Single Number III
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an integer array nums in which **exactly two** elements appear only once, and **every other** element appears exactly twice.
Return the two elements that appear only once. You may return the answer in any order.
Design your algorithm so that it runs in **linear time** and uses only **constant extra space**.
A common approach: XOR-ing every value together cancels out all the paired numbers and leaves the XOR of the two unique values combined. Since those two values differ, that combined XOR has at least one set bit — and that bit lets you split the array into two groups, isolating one unique number in each.
Examples
Constraints
- `2 <= nums.length <= 3 * 10^4`
- `-2^31 <= nums[i] <= 2^31 - 1`
- Exactly two elements appear once; all other elements appear exactly twice.
- The result must use O(1) extra space and run in O(n) time.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.