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.
MediumTechnical
105 practiced
Implement shortest_path_grid(grid, start, target) in Python using BFS with a queue. The grid is a 2D matrix where 0 = free cell and 1 = obstacle. Return the shortest path length or -1 if unreachable using 4-directional moves. Include boundary checks, visited handling, and sample inputs.
HardTechnical
71 practiced
Design a full-featured expression evaluator that supports variables, function calls, operator precedence, and safe evaluation under a constrained call stack size. Describe parsing strategy (tokenizer, shunting-yard or Pratt parser), AST construction, and evaluation model that avoids deep recursion if stack space is limited.
MediumTechnical
62 practiced
Design and implement a MinStack in Python that supports push(x), pop(), top(), and getMin() each in O(1) time. Provide two approaches: auxiliary stack of minimums and value encoding trick. Explain space complexity and handling of duplicates.
HardTechnical
70 practiced
Given a histogram as an array of heights, implement largest_rectangle_area(heights) in Python using a stack to compute the largest rectangle area in O(n) time. Provide explanation of the monotonic stack strategy, sentinel usage, and proof sketch for correctness.

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.