Search⌘ K
AI Features

Solution: Find the Corrupt Pair

Explore how cyclic sort helps identify the corrupt pair—missing and duplicated numbers—in an unsorted array with elements from 1 to n. This lesson teaches you to swap elements in place to restore order, then detect discrepancies to find the corrupt pair efficiently in linear time using constant space.

Statement

We are given an unsorted array, nums, with nn elements and each element is in the range [1,n] ...