← Google Interview Insights

Google·Data Scientist·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Interviewed for a Data Scientist role at Google and got a Python coding question about list deduplication. Pretty standard algorithmic problem but the in-place vs return-new-list framing tripped me up for a second.

Questions Asked (1)

Q1

Write a Python function that removes duplicate elements from a list while preserving the order in which items first appeared.

Algorithms & Data Structures
Author's notes

My first instinct was to just use a set and call it a day, which obviously kills the order.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: the function should remove duplicates while preserving the original order of first occurrences. Then, present an efficient solution using a set to track seen elements and a list to build the result, and discuss time and space complexity.

Pro tip: Mention that Python 3.7+ dictionaries preserve insertion order, so `list(dict.fromkeys(lst))` is a concise and efficient one-liner. However, be prepared to explain the underlying mechanism and its O(n) complexity.

1. Clarify requirements and edge cases

Confirm that the list can contain any hashable elements, and discuss handling of unhashable types if necessary. Ask about input size and whether the original list should be modified.

2. Choose an approach

Decide between using a set for O(1) lookups or leveraging ordered dictionaries. Consider trade-offs between readability and performance.

3. Implement the solution

Write clean, Pythonic code. For example, use a loop with a set, or use `dict.fromkeys` for a concise solution.

4. Analyze complexity

State that the time complexity is O(n) on average and space complexity is O(n) due to the additional data structures.

5. Test with examples

Walk through a few test cases, including empty list, all duplicates, and mixed types, to demonstrate correctness.

Key Points to Mention

  • Time complexity: O(n) with set or dict, versus O(n^2) with naive nested loops.
  • Space complexity: O(n) for the set/dict and result list.
  • Python's ordered dict (3.7+) and `dict.fromkeys` as a concise solution.
  • Handling unhashable elements (e.g., lists) by converting to tuples or using a different approach.
  • Preserving order of first occurrence, not last.
  • Edge cases: empty list, single element, all duplicates.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.