PracHub
QuestionsLearningGuidesInterview Prep

Quick 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.

  • medium
  • Google
  • Coding & Algorithms
  • Data Scientist

Remove Duplicates While Preserving Order in List

Company: Google

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

##### Scenario A data pipeline receives an unordered list of IDs containing duplicates; downstream components require a duplicate-free list while preserving original arrival order. ##### Question Write a Python function remove_duplicates(lst) that deletes all duplicate elements from a list in place (or returns a new list) while keeping only the first occurrence of each item. ##### Hints Iterate while maintaining a set of seen elements; avoid O(n^ 2) solutions.

Quick Answer: 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.

Given a list of integer IDs lst, return a new list that contains each value from lst exactly once, preserving the order of first occurrence. Keep only the first time each value appears and discard subsequent duplicates.

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

  1. Use a set to track seen values.
  2. Append an element to the result only if it has not been seen.
  3. Avoid repeated membership checks on a list, which lead to O(n^2) time.
Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 9,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Count Rectangle Coverage on a Grid - Google (easy)
  • Deduplicate and Order Batch and Streaming Logs - Google (medium)
  • Count Overlapping Rectangle Updates on a Grid - Google (hard)
  • Find A Threshold-Limited Path With Minimum Required Safety - Google (medium)
  • Filter Repeated Robot Status Messages - Google (medium)