Baseline Arrays · Easy O(n) · O(1)
An access-control system issues badges numbered 0 through n, and an end-of-day audit dumps every badge that badged in exactly once. Exactly one badge is missing from the dump. Identify it without sorting the attendance log.
Input: An array nums of n distinct integers drawn from the range [0, n].
Output: The single integer in [0, n] that does not appear in nums.
1 <= n <= 10^40 <= nums[i] <= nAll values in nums are distinctInput: {"nums":[3,0,1]}
Output: 2
The badges 0,1,3 checked in, so the untouched badge in [0,3] is 2.
Input: {"nums":[0,1]}
Output: 2
With two entries present, the range is [0,2] and the absent badge is the upper bound itself.