Traversal interview questions
Practice 32 questions on traversal. Each runs in a real in-browser editor with Jest tests and a worked, diagram-backed solution.
32 questions
- EASY
Binary Tree Equal
Implement a function that returns whether two binary trees have identical structure and node values.
15 minAlgorithms - EASY
Binary Tree Maximum Depth
Implement a function that returns the maximum depth from root to leaf in a binary tree.
15 minAlgorithms - EASY
Flip Binary Tree
Implement a function that mirrors a binary tree by swapping the left and right children of every node.
15 minAlgorithms - MEDIUM
Binary Search Tree Kth Smallest Element
Implement a function that returns the kth smallest value in a binary search tree.
25 minAlgorithms - MEDIUM
Binary Search Tree Lowest Common Ancestor
Implement a function that finds the lowest common ancestor of two nodes in a binary search tree.
25 minAlgorithms - MEDIUM
Binary Tree
Build a binary tree data structure with the essential insert, traverse, and search operations.
25 minAlgorithms - MEDIUM
Binary Tree Level Order Traversal
Implement a function that returns the values of a binary tree grouped by level from top to bottom.
25 minAlgorithms - MEDIUM
Binary Tree Subtree
Implement a function that determines whether one binary tree appears as a subtree of another.
25 minAlgorithms - MEDIUM
Breadth-First Search
Implement breadth-first traversal of a directed graph, visiting nodes level by level from a start vertex.
25 minAlgorithms - MEDIUM
Corresponding Node Across Pages
Implement a function that locates the node in a mirrored DOM tree occupying the same path as a given node.
25 minJavaScript - MEDIUM
Count Islands in a Grid
Implement a function that counts the number of distinct islands of connected cells in a 2D binary grid.
25 minAlgorithms - MEDIUM
Deep Map
PREMIUMImplement a function that walks an arbitrarily nested structure and applies a transform to every leaf value.
25 minJavaScript - MEDIUM
Depth-First Search
Implement depth-first traversal of a directed graph, exploring each branch fully before backtracking.
25 minAlgorithms - MEDIUM
Find Word in Grid
Implement a function that checks whether a target word can be traced through adjacent cells in a 2D character grid.
25 minAlgorithms - MEDIUM
getElementsByClassName
Implement a function that returns all DOM elements containing every one of the specified class names.
25 minJavaScript - MEDIUM
getElementsByStyle
Implement a function that returns all DOM elements whose computed style matches a given property and value.
25 minJavaScript - MEDIUM
getElementsByTagName
Implement a function that walks a DOM tree and returns every descendant element matching a given tag name.
25 minJavaScript - MEDIUM
Graph Clone
Implement a function that produces a deep copy of a connected, undirected graph given a reference node.
25 minAlgorithms - MEDIUM
HTML Sanitizer
Implement a simplified HTML sanitizer that strips out unsafe tags and attributes from a given DOM tree.
25 minJavaScript - MEDIUM
HTML Serializer
Implement a function that serializes a tree-shaped object into a pretty-printed HTML string with indentation.
25 minJavaScript - MEDIUM
Is the Graph a Tree
Implement a function that determines whether a given undirected graph forms a valid tree.
25 minAlgorithms - MEDIUM
Matrix Spiral Traversal
Implement a function that walks a 2D matrix in clockwise spiral order and returns the visited values.
25 minAlgorithms - MEDIUM
Ocean Flow
Implement a function that returns every grid cell from which water can flow to both the Pacific and Atlantic oceans.
25 minAlgorithms - MEDIUM
Squash Object
Implement a function that flattens a nested object into a single-level object using dot-delimited keys.
25 minJavaScript - MEDIUM
Validate Binary Search Tree
Implement a function that determines whether a binary tree satisfies the binary search tree ordering invariant.
25 minAlgorithms - HARD
Binary Tree Serialization and Deserialization
PREMIUMImplement functions that convert a binary tree to a string and reconstruct the same tree back from that string.
40 minAlgorithms - HARD
Dijkstra's Algorithm
PREMIUMImplement Dijkstra's algorithm to compute shortest paths from a source vertex in a weighted graph.
40 minAlgorithms - HARD
getElementsByTagNameHierarchy
PREMIUMImplement a function that finds all DOM elements matching an ancestor-to-descendant tag-name hierarchy.
40 minJavaScript - HARD
Lowest Hiding Element
PREMIUMImplement a function that finds the deepest common ancestor whose hiding would conceal every target element.
40 minJavaScript - HARD
Table of Contents
PREMIUMImplement a function that walks an HTML document's headings and builds a nested table of contents.
40 minJavaScript - HARD
Text Between Nodes
PREMIUMImplement a function that gathers the text content lying between two DOM nodes in document order.
40 minJavaScript - HARD
Topological Sort
PREMIUMImplement a function that returns a topological ordering of nodes in a directed acyclic graph.
40 minAlgorithms