Search⌘ K
AI Features

Solution: Missing Number

Explore this lesson to understand how to identify a missing number in an array of distinct integers using the cyclic sort technique. Learn to implement an efficient O(n) time complexity algorithm that sorts elements in-place and detects the first index mismatch to find the missing number, optimizing both time and space complexity.

Statement

Given an array, nums, containing nn distinct numbers in the range [0,n][0, n], return the only number in the range that is missing from the array.

Constraints:

  • n=n = nums.length
  • 1n1031 \leq n \leq 10^3
...