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
71 practiced
Implement mergeTwoLists(l1, l2) that merges two sorted singly linked lists into one sorted list. Write in Python, Java, or C++ and ensure O(n1 + n2) time and O(1) extra space (excluding output). Example: l1=[1,3,5], l2=[2,4] → [1,2,3,4,5]. Discuss use of a dummy head and pointer manipulation.
HardTechnical
134 practiced
Some doubly linked lists include nodes with a child pointer pointing to another doubly linked list (multilevel). Implement flatten(head) that flattens the list depth-first into a single-level doubly linked list in-place. Provide both recursive and iterative approaches and discuss stack depth and in-place splicing of next/prev pointers.
HardTechnical
82 practiced
Implement kthSmallest(root, k) to find the k-th smallest element in a BST. Provide both iterative stack-based inorder and Morris traversal (O(1) space) approaches and discuss trade-offs. Mention augmenting nodes with subtree sizes for repeated queries to achieve O(log n) runtime per query.
HardSystem Design
88 practiced
Beyond token-based string serialization, design a compact binary serialization for a binary tree optimizing for space (e.g., bit-level packing for null markers and varint encoding for integers). Describe an encoding scheme, a streaming parser, how you handle endianness and versioning, and trade-offs between compactness and CPU parsing cost.
MediumTechnical
90 practiced
Implement isBalanced(root) to check whether a binary tree is height-balanced (for every node, left and right heights differ by at most 1) in O(n) time. Avoid repeated height computations by using a helper that returns height or a sentinel for imbalance. Provide proof sketch for correctness.

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.