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 recursive functions inorder(root), preorder(root), and postorder(root) that return arrays of node values for a binary tree. Use Python, Java, or C++ and demonstrate with example: root=1,left=2,right=3 -> preorder [1,2,3], inorder [2,1,3], postorder [2,3,1]. Explain time and space complexity and recursion base cases.
MediumTechnical
0 practiced
Design serialize(root) and deserialize(data) functions to convert a binary tree to a string and back. Support nulls and ensure unique reconstruction. Implement in Python/Java/C++ using preorder or level-order encoding with null markers. Analyze time/space complexity and mention practical parsing considerations.
MediumTechnical
0 practiced
Implement removeNthFromEnd(head, n) that removes the n-th node from the end of a singly linked list in one pass, O(n) time and O(1) space. Use the two-pointer technique with a dummy node to handle head removal. Example: head=[1,2,3,4,5], n=2 -> [1,2,3,5]. Explain corner cases like removing the first node.
HardTechnical
0 practiced
Given a linked list where each node has next and random pointers, implement copyRandomList(head) that returns a deep copy of the list in O(n) time and O(1) extra space (excluding the output). Use the interleaving technique (clone nodes between originals). Explain steps, edge cases, and how to separate the cloned list from the original.
HardTechnical
0 practiced
Given an array of k sorted linked lists, implement mergeKLists(lists) to merge them into one sorted list. Provide two approaches: using a min-heap (priority queue) and a divide-and-conquer pairwise merge. Compare time and space complexity and discuss trade-offs when k is large or lists are unevenly sized.

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.