13. Find All Duplicates in Array

EasyArrayArray

Given an integer array nums, return all elements that appear more than once.

The answer can be in any order.

Input: An integer array nums of length n.

Output: A sorted list of all integers that appear more than once.

Examples

Example 1
Input: [4,3,2,7,8,2,3,1]
Output: [2,3]
Explanation: Frequencies: {4:1,3:2,2:2,7:1,8:1,1:1}. Elements with count>1: 2 and 3. Return [2,3].
Example 2
Input: [1,1,2]
Output: [1]
Explanation: 1 appears twice. 2 appears once. Return [1].
Example 3
Input: [1,2,3,4,5]
Output: []
Explanation: All elements appear exactly once. Return [].

Constraints

Asked by

GoogleAmazonBloombergMicrosoftMetaOracle
Solve this problem in the editor →