Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Missing Number

Easy
bit-manipulationmatharray

Array nums holds n distinct values from the range [0, n] — exactly one value is missing. Find it in O(n) time and O(1) space.

Input: one line of space-separated integers. Output: the missing value.

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

Constraints

  • 1 ≤ n ≤ 10^4
  • Values are distinct and within [0, n].
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.