Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

17. Missing Number

EasyDay 5 of 60Arrays & Hashing

The array nums holds n distinct numbers taken from the range 0 to n, so exactly one number from that range is absent. Return the missing number.

Example 1
Input: nums = [3,0,1]
Output: 2
n = 3, so the range is 0 to 3, and 2 is not in the array.
Example 2
Input: nums = [0,1]
Output: 2
n = 2, the range is 0 to 2, and 2 is missing.
Constraints
  • 1 <= n <= 10^4
  • 0 <= nums[i] <= n
  • All values are distinct
Hints
Frequently asked at: Microsoft, Amazon, Apple, TCS, Cognizant
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min