Math Fundamentals18 sections · 814 units
Open in Course

Mismatch - The Idea

Frequency tracking

You need to find which number appears twice and which is missing. Count the frequency of each number, then check which count is 22 (duplicate) and which is 00 (missing).

Use a set or frequency map. Iterate from 11 to nn and check which number is missing from the array.

The expected set is {1,2,,n}\{1, 2, \ldots, n\}. The actual array has one duplicate and one missing value. Compare the two.