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.

HardTechnical
0 practiced
Implement reorderList(head) that reorders a singly linked list in-place to follow the sequence L0→Ln→L1→Ln-1→L2→... Use O(1) extra space and O(n) time: find middle, reverse second half, and merge alternately. Provide example input and explain pointer manipulations to avoid cycles or lost nodes.
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.
MediumTechnical
0 practiced
Given a binary tree and target sum, implement countPaths(root, target) that counts the number of downward paths (start at any node, move down to children) whose node values sum to target. Aim for O(n) time using a prefix-sum hashmap. Explain why naive O(n^2) solutions are too slow and show how backtracking keeps complexity linear.
EasyTechnical
0 practiced
Write a function removeAll(head, val) in Python or Java that removes all nodes with value 'val' from a singly linked list and returns the new head. Ensure O(n) time and O(1) extra space. Explain edge cases: removing head nodes, all nodes removed, and empty list. Provide example: head=[2,3,2,4], val=2 → [3,4].
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.

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.