|Find Duplicates
All Challenges

Find Duplicates

MediumArrays

Given a list of integers nums, return a sorted list of all numbers that appear more than once.


If no duplicates exist, return an empty list.


This is a classic data cleaning problem — finding duplicate records, transaction IDs, or user entries in a dataset before processing.

Examples

Input: find_duplicates([4, 3, 2, 7, 8, 2, 3, 1])
Output: [2, 3]
2 and 3 appear twice
Input: find_duplicates([1, 1, 2])
Output: [1]
1 appears twice
Input: find_duplicates([1, 2, 3])
Output: []
No duplicates
Input: find_duplicates([5, 5, 5])
Output: [5]
5 is a duplicate, only include it once

Constraints

  • 1 <= len(nums) <= 100,000
  • Return results in sorted ascending order
  • Each duplicate should appear only once in the result
pythoneditor
Loading Python runtime…