Skip to interview prep
Apexed

10. Single Number

EasyBit manipulation

Every element in nums appears twice except one. Return the element that appears once, using constant extra space.

Example 1

Input: nums = [4, 1, 2, 1, 2]
Output: 4

Example 2

Input: nums = [2, 2, 1]
Output: 1

Constraints

  • 1 ≤ nums.length ≤ 3 × 10⁴
  • nums.length is odd

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Single Number — coding interview practice — Apexed