All practice tasks

Coding (Algo)

Find the Unpaired Value

Bit manipulation · Easy

A reconciliation export contains numeric IDs in arbitrary order. Every ID occurs exactly twice except one that occurs once. The export is already validated; your job is to find the unpaired ID without building another collection.

Return the single integer that occurs once using constant extra memory.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

A JSON object { "nums": number[] }.

Fields

  • nums contains signed 32-bit integers. Exactly one distinct value appears once; every other distinct value appears twice.

Output

Return value

  • Return the unpaired value, including its sign.
  • Zero is a valid value and a valid answer.
  • The caller guarantees the multiplicity rule; do not add a separate input-validation pass.

Constraints

  • 1 <= nums.length <= 100001 and the length is odd.
  • -2147483648 <= nums[i] <= 2147483647. These explicit bounds also apply to Python.
  • Do not sort or mutate nums.

Examples

Example 1

{
  "nums": [
    4,
    -2,
    4
  ]
}

Returns

-2

The two copies of 4 cancel; -2 is unpaired.

Example 2

{
  "nums": [
    0
  ]
}

Returns

0

A single zero is valid.

Required complexity

O(n) time and O(1) extra space

What this task practices

Find the Unpaired Value is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.