Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Remove Duplicates From Array
00:00
5 left

Remove Duplicates From Array

EasyPython

Problem

Remove duplicate from given array.

Implement remove_duplicates(nums) to return a new array containing each value only once, preserving the order of its first appearance. The input is an array of integers, and the output must be an array of integers.

Example: nums = [4, 2, 4, 1, 2] returns [4, 2, 1]. The array may contain negative values, zero, and repeated values.

Constraints

  • 0 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • Preserve the order of first occurrences
  • Return a new array and do not modify nums

Function Signature

def remove_duplicates(nums):
Interviewer

Your question is Remove Duplicates From 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.