Implement Hash Map with O(n) time
Last updated: January 24, 2026
Quick Overview
Implement a hash map that supports insert, delete, and lookup operations, all with an average time complexity of O(1). Your implementation should handle collisions using chaining or open addressing. The hash map should be able to store key-value pairs, and you should provide methods to add, remove, and retrieve values based on their keys.
Notion
January 24, 202612
6
2,589 solved
Implement a hash map that supports insert, delete, and lookup operations, all with an average time complexity of O(1). Your implementation should handle collisions using chaining or open addressing. The hash map should be able to store key-value pairs, and you should provide methods to add, remove, and retrieve values based on their keys.
This coding problem is frequently asked during Technical Screen at Notion. The interviewer is testing your ability to translate a problem into clean, working code while discussing time and space complexity. Notion expects candidates to write production-quality code, not just solve the puzzle.
What the Interviewer Expects
- Recognize the underlying problem pattern (sliding window, two pointers, BFS/DFS, etc.)
- Discuss multiple approaches and trade-offs before coding
- Implement an optimal solution with clean, production-quality code
- Handle all edge cases including boundary conditions and invalid input
- Optimize both time and space complexity with clear justification
- Test your solution systematically with well-chosen examples
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What is the worst-case input for your solution?
- What if the input doesn't fit in memory?
- How would you parallelize this solution?
- How would you test this solution thoroughly?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
The problem requires implementing a hash map that supports O(1) time complexity for insert, delete, and lookup operations. A hash map is typically implemented using a fixed-size array and a hash funct...
Approach
- Choose a Size for the Hash Map: We will initialize an array of a certain size (e.g., 10) for our hash map. This size can be adjusted based on expected load.
- Hash Function: Implement a ...