Remove duplicates from a list, keeping the order
Coding problemEasyAsked in: Cognizant
Given a list of integers, return a new list without repeats: keep the first occurrence of every value and drop the later ones, and keep the original order.
The same task often comes with text values instead of numbers; the method is the same. The largest hidden tests have 100,000 values.
Examples
Example 1
Input: nums = [3,1,3,2,1]
Output: [3,1,2]
Example 2
Input: nums = [7,7,7]
Output: [7]
Example 3
Input: nums = []
Output: []
Constraints
- The list holds between 0 and 100,000 integers
- Each value is a 32-bit integer
Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.
Run your code to see the results here. Ctrl or Cmd + Enter runs; add Shift to submit.