Remove Duplicates While Preserving Order in List
Company: Google
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates a candidate's competency in data deduplication, handling duplicate elements while preserving original order, and awareness of algorithmic time and space complexity.
Constraints
- 0 <= len(lst) <= 200000
- -10^9 <= lst[i] <= 10^9
- Preserve order of first occurrence
- Aim for O(n) average time and O(n) extra space using a hash set
- Return a new list
Hints
- Use a set to track seen values.
- Append an element to the result only if it has not been seen.
- Avoid repeated membership checks on a list, which lead to O(n^2) time.
Community answers
Answer by reemajhunjhunwala01