Show problems as
Classic problem #268EasyArrayHash TableMathBinary SearchBit ManipulationSorting

Missing Number

Real-world version: Unclaimed Badge Number
Tracked in this browser only
Read Missing Number on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A site office owns one visitor badge for each whole number from 0 up to and including n. At closing time a clerk empties the drop tray and writes down what she finds there.

You get her note as the array returned. Its length is n, no number shows up twice, and each number she wrote sits somewhere in 0 through n inclusive, so exactly one badge of the set failed to come back.

Report the number printed on the badge that is still out.

Examples

Example 1

Input
returned = [2, 5, 0, 1, 4]
Output
3

Five badges came back, so the office owns badges 0 through 5. Only 3 is absent from the tray.

Example 2

Input
returned = [0]
Output
1

One badge came back out of the pair numbered 0 and 1, and the one still out is the higher of the two.

Example 3

Input
returned = [5, 3, 1, 0, 2, 6]
Output
4

The tray covers 0 through 6 apart from 4, which never made it back.

Constraints

  • n == returned.length
  • 1 <= n <= 10^4
  • 0 <= returned[i] <= n
  • No value repeats inside returned
  • Exactly one value of 0..n is absent from returned

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def unclaimed_badge(returned: list[int]) -> int:
Java
public int unclaimedBadge(int[] returned)