Missing Number Problem
Missing Number Problem — ExecCode School DSA Practice
Solve the Missing Number problem on ExecCode. Free online school DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an array nums containing n distinct numbers taken from the range [0, n], find the single number in that range that is missing from the array. Solve it in linear time and constant extra space using the cyclic sort placement trick.
Examples
Input nums = [3, 0, 1]; Output 2. Input nums = [0, 1]; Output 2. Input nums = [9, 6, 4, 2, 3, 5, 7, 0, 1]; Output 8
Constraints
1 <= nums.length <= 10^4 0 <= nums[i] <= n All numbers in nums are unique.
Practice Missing Number free on ExecCode. Browse DSA problems, topic map, and placement guides.