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

Find Duplicates in Array

MediumPython

Problem

Write a code to Find duplicate numbers in an array

Asked in the technical interview stage. Candidate directly gave the optimal approach.

Implement def find_duplicates(nums):. Return each value that appears at least twice, exactly once, ordered by the position where its second occurrence is encountered.

Example 1: [4, 3, 4, 2, 3, 4] returns [4, 3].

Example 2: [1, 2, 3] returns [].

nums contains 0 to 10,000 integers, each between -10^9 and 10^9.

Constraints

  • 0 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • Return each duplicated value exactly once
  • Preserve the order in which values become duplicates

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.