InterviewStack.io LogoInterviewStack.io

Stacks and Queues Questions

Implementation and usage of stack and queue data structures. Problems involving balanced parentheses, expression evaluation, queue operations, or sliding window maximums. Understanding when to use each structure and their time/space trade-offs.

MediumTechnical
68 practiced
Implement an LRUCache class in Java with a constructor taking capacity and methods get(key) and put(key,value) with O(1) expected time. Do not use LinkedHashMap built-in LRU; implement using a hashmap plus a doubly linked list. Provide code skeleton and explain eviction policy and complexity.
HardSystem Design
103 practiced
You must process a very large stream of numbers to compute sliding window maxima but the window size k can be larger than available RAM and the stream is much larger than memory. Design an algorithm or system that produces exact sliding window maxima with minimal memory and disk I/O. Discuss block techniques, precomputation (prefix/suffix), trade-offs, and complexity.
HardSystem Design
74 practiced
Design an undo/redo system that supports branching history where, after undoing several steps, performing a new action creates a new branch rather than replacing the old one. Describe the data model to store branching versions, how to navigate branches, how to present branches in a UI, and how to merge or discard branches.
MediumTechnical
64 practiced
Given an array nums, implement next_greater_elements(nums) in C++ that returns an array where result[i] is the first greater element to the right of nums[i], or -1 if none. Provide an O(n) time solution using a stack and explain how it handles duplicates and monotonic properties.
MediumTechnical
76 practiced
Given a string s containing '(', ')', and '*' where '*' can represent '(', ')', or an empty string, implement valid_parenthesis_string(s) in O(n) time and O(1) extra space to decide if s can be balanced. Explain the greedy range-tracking approach and prove correctness informally.

Unlock Full Question Bank

Get access to hundreds of Stacks and Queues interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.