Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Optimize Duplicate Pair Detection

Medium
MediumCodingHash TablesArraysSortingAsked 1 times

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):
Practicing as: Engineering Manager interview at xAI

Hi, 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.

Take this as a live interview session →

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
def solve(rows):
    counts = {}
    for row in rows:
        ...
    return result
Sign up to unlock solutions
xAI Engineering Manager Interview QuestionsxAI Interview Questions
Next questions
Optimize Duplicate Detection in ArraysEasyButtonFind Duplicate Values in ArrayEasyOpenTextFind Duplicate Values in ArrayEasy