Missing Number
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.

30:00

Missing Number
easy
Topics
Companies

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.

Example 1:
Input: [3,0,1]
Output: 2
Constraints:
  • n==nums.lengthn == \text{nums.length}

  • 1n1041 \leq n \leq 10^4

  • 0nums[i]n0 \leq \text{nums}[i] \leq n

  • All values in nums are unique.

Input
arr =[3,0,1]

Find missing number in range [0, 3] using XOR

XOR Result

0

Phase

XOR indices

Array (n=3)
3
idx:0
0
idx:1
1
idx:2
Expected Range [0, 3]
0
1
2
3
Current
Missing
Present
Variables
No variables to display
DepthFunction Call
Stack empty
0/8