Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Unique Elements from a List

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

Your question is Unique Elements from a List. 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

Given a list nums of integers, return a new list containing only the unique elements from nums in the order of their first appearance. The input is a Python list, and the output must also be a Python list.

Constraints

  • 0 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • Preserve the order of first occurrence in the result

Function Signature

def unique_elements(nums):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output