All problems

Set Mismatch

Easy · hash map

A ticket machine should have printed each of the numbers 1 to n exactly once. Because of a fault, one number was printed twice and, as a result, one other number was never printed. The n printed numbers are in the list nums, in no particular order.

Return a list of two integers: first the number that appears twice, then the number that is missing.

Examples

Example 1

Input: nums = [1, 2, 2, 4]

Output: [2, 3]

2 appears twice and 3 never appears.

Example 2

Input: nums = [3, 1, 3]

Output: [3, 2]

3 appears twice and 2 never appears.

Example 3

Input: nums = [2, 2]

Output: [2, 1]

Constraints