Given an array of integers, return a new array containing only the duplicates.
The resulting array's values can be stored in any order.
Example:
Input: [2, 3, 1, 1, 4, 3, 2, 1] Output: [2, 1, 3]
Note:
Your algorithm should run in O(n) time and use O(n) extra space.
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check