← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Google SWE coding round, one design problem that looked clean on the surface but had a few gotchas once you started thinking about amortized complexity. Not the hardest thing I've seen from them but definitely took more thought than I expected.

Questions Asked (1)

Q1

Design a class that supports three operations: finding the smallest missing positive integer, filling that missing integer into the data structure, and deleting a given number. All operations should run in amortized constant time.

Algorithms & Data StructuresSystem Design
Author's notes

My first instinct was a sorted set and I immediately started going down that road before realizing find would be O(log n) at best.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the requirements and constraints, then propose a data structure that combines a hash map for O(1) membership checks with a min-heap or a doubly linked list to track missing integers. Explain how to maintain the smallest missing positive integer efficiently during insertions and deletions, ensuring amortized O(1) operations.

Pro tip: Mention that the smallest missing positive integer can be maintained by tracking a candidate value and updating it lazily, and discuss how deletions might require backtracking. This shows you understand amortized analysis and can handle edge cases.

1. Clarify Requirements

Ask about the range of numbers, expected frequency of operations, and whether the data structure needs to handle duplicates or only positive integers.

2. Choose Data Structures

Propose using a hash set for O(1) insert/delete and a min-heap or a doubly linked list to track missing numbers, or a combination of a hash map and a variable for the smallest missing.

3. Design Operations

Detail how each operation works: for findSmallest, return the tracked smallest missing; for fill, insert the number and update the smallest missing if needed; for delete, remove the number and possibly update the smallest missing.

4. Analyze Complexity

Argue that each operation is amortized O(1) by showing that updates to the smallest missing are infrequent and bounded, using potential method or aggregate analysis.

5. Handle Edge Cases

Discuss scenarios like deleting the current smallest missing, inserting a number that fills the gap, and handling large ranges or negative numbers.

Key Points to Mention

  • Use a hash set for O(1) membership checks and insertions/deletions.
  • Maintain the smallest missing positive integer with a variable and update it only when necessary.
  • Consider using a min-heap of missing numbers or a doubly linked list to track gaps.
  • Amortized O(1) can be achieved by ensuring updates to the smallest missing are infrequent.
  • Handle deletions that might cause the smallest missing to decrease by backtracking or using a priority queue.
  • Discuss trade-offs between different approaches, such as memory usage vs. time complexity.

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