Coding Challenge Practice - Question 77

Published: (December 13, 2025 at 05:45 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

Problem Description

Implement a function that finds the integer that appears only once in an array where every other integer appears exactly twice.

Solution Explanation

The XOR operation (^) has a useful property:

  • a ^ a = 0 – two identical numbers cancel each other out.
  • 0 ^ b = b – XOR with zero leaves the other number unchanged.

By XOR‑ing all elements of the array, every pair of identical numbers reduces to 0, leaving only the single, unpaired integer.

Code

function findSingle(arr) {
  let result = 0;

  for (let num of arr) {
    result ^= num;
  }

  return result;
}
Back to Blog

Related posts

Read more »

Palindrome Checker

What is a palindrome? A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward ignoring spaces, punctua...