Search⌘ K
AI Features

Solution: Single Number II

Understand how to apply bitwise XOR operations to identify two unique elements in an array where all other elements appear twice. This lesson teaches the algorithm to separate these numbers by using the rightmost set bit as a mask, enabling efficient constant space solutions for coding interviews.

Statement

Given a non-empty array arr, in which exactly two elements appear once, and all the other elements appear twice, return the two elements that appeared only once.

Note: The result can be returned in any order. The solution should use only constant extra space.

Constraints:

  • 22 \leq ...