
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,
3appears twice, and2is missing from the sequence.
- Input: nums =
-
Example 2:
- Input: nums =
[2,2,3,5,4] - Expected Output:
[2,1] - Justification:
2is duplicated, and1is missing, making2the repeated number and1the missing one.
- Input: nums =
-
Example 3:
- Input: nums =
[1,5,3,2,7,7,6] - Expected Output:
[7,4] - Justification: In this sequence,
7is the number that appears twice, and4is absent, indicating7as the duplicate and4as the missing number.
- Input: nums =
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory