LeetCode 268 | Missing Number | O(1) Space & O(n) Time Solution Explained | Pen & Paper
In this video we solve LeetCode 268 — Missing Number.
You’re given an array nums of size n containing n distinct numbers from the range [0, n]. Exactly one number from the full range is missing. Your task: find the missing number.
We’ll cover:
• Why the array of size n must have one number missing from [0,n].
• Two optimal approaches:
– The sum formula method: compute expected sum = n*(n+1)/2, subtract actual sum → missing number.
– The XOR bit-trick method: use the property x ^ x = 0, x ^ 0 = x; XOR all indices and all values to cancel pairs and leave the missing number.
Download
0 formats
No download links available.
LeetCode 268 | Missing Number | O(1) Space & O(n) Time Solution Explained | Pen & Paper | NatokHD