Skip to content
Katabench
Try free

Single Number

Easy About 8 min Free, no account needed

One value appears an odd number of times - XOR finds it for free.

The brief

In nums, every value appears an even number of times except one value, which appears an odd number of times. Return that value.

The performance bar

The obvious approach counts every element's occurrences, O(n2) on the hidden 200,000-element test, so it's too slow. You will need a single linear pass, and ideally no extra memory.

Starter code

C#
using System;

public class Solution
{
    // TODO: return the value appearing an odd number of times.
    public int SingleNumber(int[] nums)
    {
        throw new NotImplementedException();
    }
}

How it is graded

Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.

C# coding challenges →

What it practices

Bit manipulation
Use masks, shifts and XOR on the binary representation directly.

Related katas