InterviewStack.io LogoInterviewStack.io

Linked Lists and Trees Questions

Dynamic and pointer based data structures including linked lists and tree structures commonly tested in interviews. For linked lists cover node based representation, traversal, insertion at head and tail, deletion, searching, reversing a list, detecting cycles, and tradeoffs versus array based lists. For trees cover basic concepts such as binary trees and binary search trees, tree node representation, insertion and deletion in search trees, recursion patterns, and traversal algorithms including depth first search with in order pre order and post order variants and breadth first search. Also include problem solving patterns such as recursion and iterative stack or queue based approaches, analysis of time and space complexity in plain terms, and common interview tasks such as lowest common ancestor, tree balancing awareness, and converting between representations. Practice includes implementing algorithms, writing traversal routines, and reasoning about correctness and performance.

EasyTechnical
0 practiced
Implement a singly linked list class in Python suitable for ML utility code with a Node structure and methods: insert_head(value), insert_tail(value), delete_value(value), find(value), and to_list(). Ensure insert_head is O(1) and insert_tail is amortized O(1). Discuss edge cases (empty list, single node) and memory usage implications in production feature pipelines.
MediumTechnical
0 practiced
Implement has_cycle(head) in Python to detect whether a singly linked list contains a cycle using O(1) extra space and O(n) time. If a cycle exists, return the node at the start of the cycle; otherwise return None. Explain Floyd's algorithm and why resetting one pointer to head finds the cycle start.
HardTechnical
0 practiced
Given a binary tree where node values may be negative, implement max_path_sum(root) in Python that returns the maximum sum of values along any path (path may start and end at any nodes). Provide algorithmic explanation, handle negative-only trees, and justify correctness with post-order reasoning.
EasyTechnical
0 practiced
Write functions max_depth_recursive(root) and max_depth_bfs(root) in Python to compute the maximum depth (height) of a binary tree. Explain time and space complexity for both implementations and trade-offs when trees are very deep versus very wide in production model evaluation contexts.
HardTechnical
0 practiced
Explain how tries and compacted tries (radix trees) can accelerate tokenization or prefix matching in NLP pipelines. Provide insertion and lookup pseudocode for a compacted trie and analyze memory vs lookup-time trade-offs for large vocabularies used in ML systems.

Unlock Full Question Bank

Get access to hundreds of Linked Lists and Trees interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.