Set Mismatch

You are given a set [1..n] represented as an array where one number is duplicated and one number is missing. Index placement exposes the mismatch directly because one value takes another value’s rightful slot.

Input Format

nums = array with one duplicate and one missing value

Output Format

array [duplicate, missing]

Constraints

  • 2 <= nums.length <= 10^4; 1 <= nums[i] <= nums.length

Examples

Example 1:

Input:

nums = [1,2,2,4]

Output:

[2,3]

Explanation:

2 is duplicated and 3 is missing.

Example 2:

Input:

nums = [1,1]

Output:

[1,2]

Explanation:

1 is duplicated and 2 is missing.

Loading...
Set Mismatch - Sorting Based Array Problems