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.

MediumTechnical
92 practiced
Given a singly linked list where each node has an extra 'random' pointer to any node or None, implement a Python function that returns a deep copy of the list. Aim for O(n) time and O(1) extra space (no hash map). Explain the three-step weaving/unweaving technique.
EasyTechnical
94 practiced
Write a function kth_from_end(head, k) that returns the k-th node from the end of a singly linked list in one pass (O(n) time, O(1) additional space). If k is larger than the list length, return None. Use Python and explain edge cases (k <= 0, empty list).
EasyTechnical
131 practiced
Write a function in Python to reverse a singly linked list. Provide both an iterative O(n) time O(1) space solution and a recursive solution. For the recursive version, explain the stack usage and the maximum recursion depth for a list of length n. Show the Node class signature you assume.
MediumTechnical
83 practiced
Convert a sorted singly linked list to a height-balanced binary search tree (BST) in O(n) time and O(log n) stack space. Implement in Python and explain how you find the middle element without random access. Provide the ListNode and TreeNode class assumptions.
HardTechnical
87 practiced
You need to merge two large balanced trees (e.g., two BST-based indexes) representing different time ranges into one while maintaining balance. Describe algorithms to perform this merge (in-order traversal to arrays then build balanced tree vs tree-to-tree recursive merges), analyze cost, and suggest which you would pick for minimal downtime and memory use.

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.