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
Given two sorted singly linked lists, implement merge_two_sorted_lists(l1, l2) in Python that returns a merged sorted list by reusing node pointers. Implement iteratively in O(n + m) time and O(1) extra space. Show example l1 = 1->3->5 and l2 = 2->4 and resulting list.
MediumTechnical
0 practiced
Implement lowest_common_ancestor(root, p, q) for a binary tree in Python that returns the lowest common ancestor node if both p and q exist. Use single pass recursion that returns p or q when found and identifies LCA when both sides return non-null. Discuss complexity and handling when one or both nodes are missing.
EasyTechnical
0 practiced
Given a binary tree, implement is_valid_bst(root) in Python that verifies whether it satisfies binary search tree ordering. Describe both the recursive min max bounds approach and the iterative inorder sequence approach. Explain handling of duplicates and integer boundaries.
HardTechnical
0 practiced
You must serialize computation graphs representing AI model layers into a compact on-device format with quantization. Describe an algorithm that prunes constant subtrees, folds constants, encodes opcodes and operand indices compactly and reconstructs runtime graph with minimal memory and acceptable numeric stability. Discuss versioning and operator portability.
MediumTechnical
0 practiced
Write function tree_diameter(root) in Python that computes the diameter of a binary tree defined as the number of nodes on the longest path between any two nodes. Use DFS that returns subtree height and updates a global maximum diameter. Explain how to adapt to edge weighted trees and how to also return the node path.

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.