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 orderExample 1
Input: nums = [4, 1, 2, 1, 2, 2, 5]
Output: [[1, 2], [2, 3]]
Explanation: 1 appears 2 times and 2 appears 3 times. Other values appear once.
Example 2
Input: nums = [7, 7, 7, 7]
Output: [[7, 4]]
Explanation: Only 7 is duplicated, and it appears 4 times.
0 <= len(nums) <= 10^5-10^9 <= nums[i] <= 10^9