Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Set Mismatch

XPChallenge Points: 10
levelLevel: Easy

You are given an array nums that originally should contain every number from 1 to n exactly once.
However, due to an error:

  • One number appears two times

  • One number is missing

Your task is to figure out:

  • Which number appeared twice

  • Which number is missing

Return them as an array:
[duplicate, missing]

Example 1:

Input: nums = [3,1,2,5,3]

Output: [3,4]

Explanation:

The number 3 appears twice and 4 does not appear.

Example 2:

Input: nums = [2,2]

Output: [2,1]

Explanation:

The set should be {1,2}, but 2 appears twice and 1 is missing.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result