Welcome to Digitville, a peaceful town where order and precision reign supreme! ๐๏ธ
In this mathematical town, there was supposed to be a perfect list called nums containing exactly the integers from 0 to n-1, with each number appearing exactly once. However, two mischievous numbers decided to sneak back into the list for a second appearance, disrupting the town's harmony!
As the town's detective ๐ต๏ธ, your mission is to identify these two sneaky duplicate numbers that have caused the list to become longer than its intended size of n.
Goal: Return an array containing the two duplicate numbers in any order.
Example: If the list should contain [0, 1, 2, 3] but instead contains [0, 1, 1, 2, 3, 3], then numbers 1 and 3 are the sneaky duplicates!
Input & Output
Visualization
Time & Space Complexity
Single pass through the array, with O(1) hash set operations
Hash set can store up to n-2 unique elements in worst case
Constraints
- 2 โค n โค 100
- nums.length == n + 2
- 0 โค nums[i] < n
- The input is generated such that nums contains exactly two repeated elements
- Each repeated element appears exactly twice