← LinkedIn Interview Insights

LinkedIn·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

LinkedIn coding interview, one question about designing a phone book from scratch. Pretty straightforward on the surface but the follow-up about reverse lookups is where things get interesting.

Questions Asked (1)

Q1

Design a phone book data structure that supports adding a name/number pair, removing an entry by name, looking up a number by name, and finding all names associated with a given number. Walk through your data structure choices and the time complexity of each operation.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

The add/remove/lookup by name part is basically just a hash map and I got through that fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and constraints, such as whether names are unique and if multiple numbers per name are allowed. Then propose a dual-index design using two hash maps: one mapping name to number(s) and another mapping number to a set of names. Walk through each operation, explaining how the maps are updated and analyze the time complexity, noting that all operations are O(1) on average.

Pro tip: Mention that the number-to-names index is crucial for the reverse lookup, and discuss how to handle updates (e.g., when a name's number changes) to maintain consistency between the two maps.

1. Clarify Requirements

Ask whether a name can have multiple numbers, whether a number can be associated with multiple names, and if names are unique. This determines the data structures needed.

2. Propose Data Structures

Suggest using two hash maps: nameToNumbers (name -> set of numbers) and numberToNames (number -> set of names). Explain that sets handle multiple associations and enable efficient add/remove.

3. Detail Operations

For each operation (add, remove, lookup by name, find names by number), describe how to update both maps. For add: insert into both maps; for remove: delete from both maps and clean up empty sets.

4. Analyze Complexity

State that all operations are O(1) average time due to hash map lookups, with O(k) for iterating over sets where k is the number of associated entries. Mention worst-case O(n) for hash collisions but assume average case.

5. Discuss Trade-offs and Extensions

Compare with alternatives like a single map or a trie, and discuss how to handle updates (e.g., changing a number) and potential memory overhead. Mention scalability considerations for large datasets.

Key Points to Mention

  • Use of two hash maps to support bidirectional lookup efficiently.
  • Handling of multiple numbers per name and multiple names per number using sets.
  • Time complexity: O(1) average for add, remove, and lookups; O(k) for retrieving all names for a number.
  • Space complexity: O(n) where n is total number of associations.
  • Consistency maintenance when updating or removing entries (e.g., removing a name from numberToNames when its last number is removed).
  • Potential need for thread safety or concurrency control in a real-world system.

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