All problems
Find Missing and Duplicate
Problem
An array of length n contains the integers 1 through n with exactly one value duplicated and one value missing.
Scan the array with a set to find the duplicated value, then scan 1 through n to find the value that never appears.
Return [duplicate, missing].
Hint
A set tells you both which value repeats and which of 1..n is absent.
Test cases
case 1
in: [[1,2,2,4]]
expected: [2,3]
case 2
in: [[1,1]]
expected: [1,2]
case 3
in: [[2,3,3,4]]
expected: [3,1]
case 4
in: [[1,2,3,4,4]]
expected: [4,5]
Starter codePython
def find_missing_duplicate(nums):
# Your code here
pass4 test cases · run your code against them in the editor