‹ DS&A interview · Socratic
DSA · Math / bit manipulation · #26

Missing Number

Module 29 · difficulty 1/5·30:00starts on first keystroke

Given an array `nums` containing `n` distinct numbers in the range `[0, n]`, return the only number in the range that is missing from the array.

Examples
  • nums = [3,0,1] 2
  • nums = [0,1] 2
  • nums = [9,6,4,2,3,5,7,0,1] 8

Stuck? Reveal an animated walkthrough of the approach.

Constraints
  • · n == nums.length
  • · 1 <= n <= 10^4
  • · 0 <= nums[i] <= n
  • · All numbers are distinct.
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.