Find Missing Number
You are given an array containing n distinct numbers taken from the range 0 to n. This means the array should ideally contain all numbers from 0 to n, but one number is missing. Your task is to find and return that missing number.
Input: An array of n integers where each integer is unique and lies between 0 and n (inclusive) except for one missing number.
Output: Return the missing number.
Example Inputs & Outputs
// 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 // Example 4: Input: [0] Output: 1
Constraints & Edge Cases
- The array contains exactly
nnumbers. - All numbers are unique.
- Numbers are in the range
0ton. - Only one number is missing from the sequence.
- The array may be in any order.
- Edge case: missing number could be
0orn.
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
