← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Interviewed at Google, got asked a string manipulation question that felt deceptively simple at first.

Questions Asked (1)

Q1

How would you remove duplicate characters from a string?

Algorithms & Data Structures
Author's notes

Went straight for a hash set approach and it felt fine, but I kept second-guessing whether they wanted me to preserve order or not.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: ask about character set (ASCII vs Unicode), whether case matters, and if the order of remaining characters should be preserved. Then present a solution using a hash set to track seen characters, building the result in a single pass, and discuss time/space complexity. If order doesn't matter, mention alternative approaches like sorting or using a boolean array for ASCII.

Pro tip: Always discuss trade-offs between time and space, and mention edge cases like empty strings or all duplicates. At Google, interviewers value clean, efficient code and the ability to adapt to constraints, so be prepared to optimize for memory if the character set is small (e.g., ASCII).

1. Clarify requirements

Ask about the character set (ASCII, Unicode), case sensitivity, and whether the order of characters must be preserved. This shows attention to detail and avoids incorrect assumptions.

2. Choose data structure

Select an appropriate data structure to track seen characters. For general cases, a hash set is efficient; for ASCII, a boolean array of size 128 or 256 is more memory-efficient.

3. Design algorithm

Iterate through the string, and for each character, check if it's in the set. If not, add it to the set and append it to the result. This preserves order and runs in O(n) time.

4. Analyze complexity

State the time complexity O(n) and space complexity O(k) where k is the number of unique characters. Discuss how this changes with different data structures.

5. Handle edge cases and alternatives

Mention edge cases like empty string, null input, or all duplicates. If order doesn't matter, discuss alternative approaches like sorting or in-place removal for mutable strings.

Key Points to Mention

  • Time and space complexity analysis
  • Choice of data structure (hash set vs boolean array) based on character set
  • Preservation of original order
  • Handling of edge cases (empty string, null, all duplicates)
  • Alternative approaches when order doesn't matter (e.g., sorting)
  • In-place modification if the string is mutable (e.g., char array in Java)

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