Implement Stack with streaming input
Last updated: December 13, 2025
Quick Overview
Implement a LRU Cache that supports get and put in O(1) time.
Walmart
Coding & Algorithms
Software Engineer
Walmart
December 13, 2025Software Engineer
Onsite
Coding & Algorithms
Medium
169
11
3,118 solved
Implement a LRU Cache that supports get and put in O(1) time.
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.
Practice a Similar Problem on Codemia
Solve a related problem with our interactive workspace, get AI feedback, and view detailed solutions.
Solve on CodemiaSample Answer
Problem Analysis
In this problem, we need to implement an LRU (Least Recently Used) Cache that supports 'get' and 'put' operations in O(1) time complexity. The LRU Cache should store a limited number of key-value pair...
Approach
To implement the LRU Cache, we will use a combination of a HashMap and a Doubly Linked List. The steps are as follows:
- Initialize:
- Create a HashMap to store key-value pairs.
- Create a...
Submit Your Answer
Markdown supported