EasyBit Manipulation · Math · Array

Missing Number

Given an array nums of n distinct integers from the range [0, n], return the one number in the range that is missing. Follow-up: O(n) time and O(1) extra space.

nums = [1,2,3] → 0nums = [0,2] → 1

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Variables

The data structures the code is building

nums and the range [0, n]

Lines link each value to its slot in the range

Time and space complexity

n = len(nums). The highlighted row is the solution being traced.

Keyboard: ← → step, Space play or pause. Up to 14 distinct numbers from 0 to n.