Back to course home
0% completed
Vote For New Content
Set Mismatch (easy)
Problem Statement
You are given an array nums
of size n
, originally containing 1
to n
integers. Unfortunately, due to some error
, one number got duplicated
, replacing
another number that now goes missing
from the sequence.
Identify the duplicated number
and the missing number
and return them as a pair
.
Examples
-
Example 1:
- Input: nums =
[1,3,3,4]
- Expected Output:
[3,2]
- Justification: Here,
3
appears twice, and2
is missing from the sequence.
- Input: nums =
-
Example 2:
- Input: nums =
[2,2,3,5,4]
- Expected Output:
[2,1]
- Justification:
2
is duplicated, and1
is missing, making2
the repeated number and1
the missing one.
- Input: nums =
-
Example 3:
- Input: nums =
[1,5,3,2,7,7,6]
- Expected Output:
[7,4]
- Justification: In this sequence,
7
is the number that appears twice, and4
is absent, indicating7
as the duplicate and4
as the missing number.
- Input: nums =
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Examples
Try it yourself