Given an array of integers nums representing identifiers from a large dataset, return a list of all values that appear more than once.
Each duplicated value should appear exactly once in the result, and the result must be sorted in ascending order. If no duplicates exist, return an empty list.
Function Signature
def find_duplicates(nums: list[int]) -> list[int]:
Rules
-
A value counts as duplicated when it occurs two or more times in
nums
. A value that occurs three or more times is still listed once.
-
Sort the result in ascending numeric order, so negative values come before positive ones.
-
Return
[]
when every value is unique.
Constraints
-
1 <= len(nums) <= 10^5
-
-10^9 <= nums[i] <= 10^9
Examples
Input: nums = [1, 2, 3, 2, 4, 5, 3, 6]
Output: [2, 3]
2 appears twice and 3 appears twice. Every other value appears once, and the sorted result is [2, 3].
Input: nums = [1, 2, 3, 4, 5]
Output: []
All elements are unique, so the result is an empty list.
Input: nums = [5, -1, 5, 5, -1, 0]
Output: [-1, 5]
5 appears three times and -1 appears twice, so each is listed once. 0 appears once and is left out, and -1 sorts before 5.