Back to problems

Find Missing and Duplicate Number in an Array

Algorithm · Salesforce · Medium

You are given an array nums of length n. Every integer from 0 to n-1 should appear exactly once, but a mistake has occurred: one value shows up twice, and because of this, one value from that range never appears at all. Determine the duplicated number and the missing number. Return a two‑element integer array with the duplicate first and the missing second: [duplicate, missing]. The input array is not sorted. Aim for a solution that runs in $$O(n)$$ time and requires only…

Checking your access…