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 SinglyLinkedList class with methods insert_head(value) and insert_tail(value) in Python or Java. Ensure insert_tail runs in O(1) time by maintaining a tail pointer. Describe time and space complexity, and show sample usage inserting [1,2,3] at tail and at head. Explain edge cases such as empty list and single-node list.
MediumTechnical
0 practiced
Given only a pointer/reference to a node in a singly linked list (no access to head), implement deleteGivenNode(node) that removes that node from the list. Discuss limitations (cannot delete the tail) and edge cases. Provide a safe implementation in C++/Java/Python and explain cost and semantics.
HardTechnical
0 practiced
Design an immutable (persistent) singly linked list API that supports O(1) prepend and O(n) append. Describe how versions share nodes to save memory, implement operations (prepend, head, tail), and discuss memory usage and GC implications in a multi-threaded read-heavy environment. Sketch code or pseudocode for basic operations.
MediumTechnical
0 practiced
Implement an LRUCache class with methods get(key) and put(key, value) in O(1) time using a doubly linked list and hashmap. Support integer keys/values and a capacity parameter. Implement in Python or Java/C++. Describe eviction policy, memory usage, and concurrency considerations for multi-threaded access.
HardTechnical
0 practiced
Given preorder and inorder traversal arrays of a binary tree, reconstruct the original tree using recursion. Implement buildTree(preorder, inorder) in O(n) time using a hashmap for inorder indices. Explain how you split ranges and why using hashmap avoids O(n^2) behavior.

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.