InterviewStack.io LogoInterviewStack.io

Linked Lists, Stacks, and Queues Questions

Covers core singly and doubly linked list concepts and the fundamental abstract data types stack and queue. For linked lists this includes node structure, traversal, insertion at head and tail, deletion, reversal, finding middle, merging, detecting cycles, removing duplicates, intersection detection, and pointer manipulation details for languages with manual memory management. For stacks and queues this includes LIFO and FIFO semantics, push, pop, peek, enqueue, dequeue, circular buffer implementations, and implementing one with the other (for example queue with two stacks). Also includes array versus linked list implementations, complexity analysis for time and space, and common algorithmic patterns that use these structures (for example bracket matching, reverse polish notation evaluation, depth first search using a stack, breadth first search using a queue, sliding window and monotonic queue techniques). Interviewers assess correct implementation, edge case handling, performance tradeoffs, and ability to choose the appropriate structure or approach for a problem.

EasyTechnical
44 practiced
Given the following C++ singly linked list Node:
cpp
struct Node { int val; Node* next; };
Describe correct deletion of a node and how to avoid memory leaks and dangling pointers. Explain how you would manage ownership with unique_ptr/shared_ptr in modern C++ in the context of ML code that integrates native layers with Python bindings.
EasyTechnical
36 practiced
Explain Floyd's Tortoise and Hare algorithm for cycle detection in a singly linked list. Describe how to find the cycle's start node after detecting a cycle, and give time and space complexity. Mention how this is relevant when debugging pointer-based data structures in lower-level ML components (e.g., C++ memory pools).
EasyTechnical
44 practiced
Implement a queue using two stacks in Python. Provide enqueue(x) and dequeue() with amortized O(1) time. Explain the amortized analysis and what happens in worst-case single operations. Discuss how this pattern might be used to implement an asynchronous buffer in a microservice that only exposes stack-like primitives.
EasyTechnical
74 practiced
Implement a basic singly linked list in Python with these operations: insert_head(value), insert_tail(value), delete(value), and to_list(). Use the following Node skeleton:
python
class Node:
    def __init__(self, val, next=None):
        self.val = val
        self.next = next
Ensure insert_tail is O(1) amortized time. Handle empty list edge cases.
EasyTechnical
49 practiced
Describe the algorithm that uses a stack to validate balanced brackets in a string (e.g., "()[]{}"), and state time/space complexity. Provide a short Python-style pseudocode snippet and explain one real ML engineering use case where bracket matching or expression validation matters (for example, parsing model configuration or computation graph expressions).

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.