Missing Number — Cyclic Sort & Index Tricks

A lab received all but one of its numbered tubes; report the one number that never arrived from the received list.

Cyclic Sort & Index Tricks · Easy

The problem

A hospital lab numbered its specimen tubes 0 through n, but only n distinct tubes arrived, so exactly one number in that range never arrived. You are given the list of received tube numbers; return the missing one.

The story

A hospital lab numbers its specimen tubes 0 to n but received only n of them, all different, so exactly one number never arrived. You have the list of received numbers, 1 to 12 of them. Which specimen number is missing?

What to return

Constraints

Example

Input
nums = [2, 0, 3]
Output
1

Solve it

More in Cyclic Sort & Index Tricks

All algorithm problems