Medium · Arrays

Find duplicate and missing

Given an array nums of n integers whose values should be exactly 1..n, where one value appears twice and one value is missing, return [duplicate, missing].

Examples

Example 1

[1,2,2,4] → dup 2, miss 3

Output: dup 2, missing 3

Example 2

[1,2,4,4,5] → dup 4, miss 3

Output: dup 4, missing 3

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Arrays problems