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
0 practiced
Implement reverse_sublist(head, m, n) in Python to reverse nodes in a singly linked list from position m to n inclusive in one pass. Positions are 1-based. Use a dummy node to handle head modifications and achieve O(n) time and O(1) space. Validate inputs and explain pointer updates during reversal.
MediumTechnical
0 practiced
Implement merge_k_sorted_lists(lists) in Python where lists is an array of k sorted singly linked list heads. Implement an O(N log k) solution using a min-heap and analyze time O(N log k) and extra space O(k), where N is total number of nodes. Discuss alternatives such as divide and conquer merge.
EasyTechnical
0 practiced
Write a function find_middle(head) that returns the middle node of a singly linked list. For even length lists return the second middle node. Implement using slow and fast pointers and analyze time and space complexity. Provide example lists to illustrate behavior and discuss how to change to return the first middle when even.
EasyTechnical
0 practiced
Implement two methods for a singly linked list in Python: insert_head(value) and insert_tail(value). Provide a LinkedList class that maintains head and optionally tail pointer. Explain time complexity for each operation and show how maintaining a tail pointer enables O(1) tail insertion. Include handling of empty list and edge cases.
MediumTechnical
0 practiced
Implement get_intersection_node(headA, headB) to find the intersection node of two singly linked lists by reference in O(n + m) time and O(1) space. Implement the two-pointer switching trick that makes pointers traverse equal total distances and meet at intersection or null. Provide proof sketch of 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.