Arrays · Coding problem
Set Mismatch
A free coding problem from the Array Hashing skill. Read it here, then solve it in the app in Java or Python.
- Easy
- Coding problem
- Free
- Java and Python
The problem
nums was meant to hold every number from 1 to n exactly once, where n is its length. A mistake crept in: one number was written twice, and so another number never made it in. Return [duplicate, missing].
Example
Input: nums = [3, 1, 5, 3, 2]
Output: [3, 4]
3 appears twice; 4 is missing.
Constraints
2 <= n <= 2 * 10^51 <= nums[i] <= n- Exactly one value in
1..nappears twice, and exactly one is missing
How it's graded
- Run checks your code against the examples. Submit also runs a hidden suite in four groups - basic cases, edge cases, random inputs and performance tests at the size limit - and shows which groups pass, never the hidden inputs.
- Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.
- Once you pass, you see the approaches from brute force to optimal, and where your solution lands among them.
More problems in Array Hashing
Solve it Set Mismatch free
No card needed. Lessons, practice questions and easy problems are free forever.
Free plan, no card · 7-day Pro trial · Cancel anytime