Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

Solution: Two Single Numbers

Problem Statement

In a non-empty array of numbers, every number appears exactly twice except two numbers that appear only once. Find the two numbers that appear only once.

Example 1:

Input: [1, 4, 2, 1, 3, 5, 6, 2, 3, 5]
Output: [4, 6]

Example 2:

Input: [2, 1, 3, 2]
Output: [1, 3]

Constraints:

  • 1 <= nums.length <= 3 * 10<sup>4</sup>
  • -3 * 10<sup>4</sup> <= nums[i] <= 3 * 10<sup>4</sup>
  • Each element in the array appears twice except for two element which appears only once.

.....

.....

.....

Like the course? Get enrolled and start learning!
Leandro Casuso

Leandro Casuso

· 9 days ago

In C# (and probably in multiple other languages), these two expressions are equivalent to get the rightmost set bit:

int rightmostSetBit = 1; while ((rightmostSetBit & n1xn2) == 0) { rightmostSetBit = rightmostSetBit << 1; }
int rightmostSetBit = n1xn2 & -n1xn2;
Show 1 reply
S

Seif Mamdouh

· 4 years ago

Where can I find a diagram with to understand the logic of this algothrim?

Show 1 reply

Reading Progress

0%


Vote for new content