Your question is Optimize Duplicate Pair Detection. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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.
nums, a list of integers[value, count] for every integer that appears at least twicevalue in ascending orderdef find_duplicates(nums):