Set Mismatch Problem

Set Mismatch Problem — ExecCode Easy DSA Practice

Solve the Set Mismatch problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

You have a set of numbers that should contain every integer from 1 to n exactly once, but one number got duplicated in place of another, which is now missing. Given the corrupted array nums, return an array [duplicate, missing] using cyclic sort in O(n) time.

Examples

Input nums = [1, 2, 2, 4]; Output [2, 3]. Input nums = [1, 1]; Output [1, 2]. Input nums = [3, 2, 3, 4, 6, 5]; Output [3, 1]

Constraints

2 <= nums.length <= 10^4 1 <= nums[i] <= nums.length Exactly one number is duplicated and exactly one number is missing.

Practice Set Mismatch free on ExecCode. Browse DSA problems, topic map, and placement guides.