DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Array

Missing Number

**Problem Statement:** 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. **Hint / Expected Approach:** XOR or Gauss sum trick **Edge Cases to Consider:** - (1) Missing 0 - (2) Missing n (last element) - (3) Single-element array

Examples

Example 1
Input: [3, 0, 1]
Output: 2
Example 2
Input: [0, 1]
Output: 2
Example 3
Input: [9,6,4,2,3,5,7,0,1]
Output: 8

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪Missing 0
  • ▪Missing n (last element)
  • ▪Single-element array
Frequently Asked At
AmazonMicrosoftGoogleTCSWipro