Problem
At Stripe, an existing utility scans a list of integers with nested loops to find values that appear more than once. Rewrite it for better performance.
Implement a function find_duplicates(nums) that returns all distinct duplicate values in ascending order, along with how many times each value appears.
Formal Specification
- Input:
nums, a list of integers - Output: a list of lists, where each element is
[value, count]for every integer that appears at least twice - The result must be sorted by
valuein ascending order
Constraints
- 0 <= len(nums) <= 10^5
- -10^9 <= nums[i] <= 10^9
- Return each duplicated value once with its total frequency
- Output must be sorted by value in ascending order
Function Signature
def find_duplicates(nums):
Practicing as: Engineering Manager interview at xAIHi, I'll play your xAI interviewer for the Engineering Manager role. Candidates describe these interviews as mixed and moderately difficult, so expect me to be professional and fair. Take your time with the question above and answer like we're in the room.
You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

