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
0 practiced
Write a Python function to reverse a singly linked list. Provide both iterative and recursive approaches and discuss stack depth, space complexity, and when each approach is preferable in production ML code (e.g., recursion depth limits vs iterative safety). Use this Node definition:
python
class Node:
    def __init__(self, val, next=None):
        self.val = val
        self.next = next
MediumTechnical
0 practiced
Explain how you would remove duplicates from an unsorted singly linked list in-place. Provide two approaches: (1) using extra memory for speed, (2) without extra memory but higher time complexity. Analyze time and space complexity and discuss which is preferable when processing streaming feature IDs in ML pipelines.
HardTechnical
0 practiced
You're engineering a memory pool that stores small fixed-size tensor metadata nodes linked in a freelist (singly linked). Propose a memory layout and freelist design that minimizes fragmentation and allocation overhead. Explain how you would implement allocation and deallocation in C++ to be safe and efficient for high-throughput ML training.
MediumTechnical
0 practiced
Implement an evaluator for Reverse Polish Notation expressions (RPN) in Python. Support integers and the operators +, -, *, /. Example: input: ['2','1','+','3','*'] -> output 9. Explain how stacks are used here and where RPN might appear in ML systems (e.g., expression-based feature computations or custom layer DSLs).
EasyTechnical
0 practiced
Implement a function in Python that finds the middle node of a singly linked list in one pass and O(1) space. If the list has even length, return the second middle node. Explain how this two-pointer technique is useful in merging or splitting data structures for parallel ML workloads.

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.