Search⌘ K
AI Features

Solution: Missing Number

Explore how to apply cyclic sort to find the missing number in an array containing distinct integers in the range [0, n]. Understand the step-by-step process to sort elements in place and identify the first mismatch between element values and their indices, resulting in a time-efficient and space-optimized solution.

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
...