Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Find Duplicates in Array
00:00
5 left

Find Duplicates in Array

MediumPython

Problem

Write code to find duplicates in an array.

Implement find_duplicates(nums) where nums is a list of integers. Return a list containing each duplicated value exactly once, ordered by the position where its second occurrence is encountered. Return an empty list when no value appears at least twice.

Constraints

  • 0 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • Return each duplicated value exactly once
  • Preserve the order in which second occurrences are encountered

Function Signature

def find_duplicates(nums):
Interviewer

Your question is Find Duplicates in Array. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.