Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Optimize Duplicate Pair Detection

EasyPython00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

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 value in 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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output