Missing Number
EasyMathBit Manipulation
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
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
Input: nums = [3,0,1]
Output: 2
n = 3, so the range is [0,3]. 2 is missing.
Input: nums = [0,1]
Output: 2
n = 2, so the range is [0,2]. 2 is missing.
Input: nums = [9,6,4,2,3,5,7,0,1]
Output: 8
Constraints
- n == nums.length
- 1 <= n <= 10^4
- 0 <= nums[i] <= n
- All the numbers of nums are unique.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.