All problems
0192EasyArrayHash TableMathBinary SearchBit ManipulationSorting

Unclaimed Badge Number

Tracked in this browser only
Write code

Trains the technique from

LeetCode 268Missing Number

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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