practice a little every day — you've got this ♡
Trees & Graphs Interview Problems
Practice 5978 original coding, SQL, system design, machine learning and behavioral problems across 15 topics. Coding and SQL problems run against hidden test cases right in your browser; every problem has hints and a worked solution, free.
- 5978
- Problems
- 2214
- Auto-graded
- 15
- Topics
- 272
- Added today
Showing 271–300 of 434 results
- Trees & GraphsMediumModel answerThreaded Comment Feed: Filtering, Nesting, and Persistent Sort
Transform a flat array of comments into a sorted, nested, filterable tree while persisting the user's sort preference across sessions.
Trees & Graphstree-constructiondfslocalStoragefrontend-data - Trees & GraphsMediumAuto-gradedShared Root of Two Nodes in a Binary Search Tree
Tests whether a candidate can exploit BST ordering to locate the deepest node that is an ancestor of both targets without searching the entire tree.
Trees & Graphsbinary-search-treelowest-common-ancestortree-traversal - Trees & GraphsMediumAuto-gradedLeft and Right View of a Binary Tree Using BFS and DFS
Tests understanding of binary tree traversal by computing boundary nodes at each depth using both breadth-first and depth-first strategies.
Trees & Graphsbinary-treebfsdfstree-traversal - Trees & GraphsMediumAuto-gradedMulti-Part Algorithm Challenge: Grids, Medians, and Traversals
Tests implementation of connected-component search in grids, efficient median computation across sorted sequences, and breadth-first and depth-first graph traversals.
Trees & Graphsgraphsarraysbinary-searchbfs - Trees & GraphsMediumAuto-gradedAssemble Tree from Edge Specifications
Tests building a tree structure from unordered edge list by tracking node relationships and identifying the root.
Trees & Graphstreeshash-tablegraph-construction - Trees & GraphsMediumAuto-gradedEqual Binary Digits and Ascending Tree Chain
Tests prefix-sum balancing for binary arrays and depth-first search for strictly increasing root-to-leaf paths in binary trees.
Trees & Graphstreesarraysprefix-sumdfs - Trees & GraphsMediumModel answerContent-Based Duplicate File Detector
Recursively scan a directory tree, group files by size then content hash, and return every set of two or more paths that hold identical bytes.
Trees & Graphshashingfile-systemtraversaldeduplication - Trees & GraphsMediumModel answerFind the Longest Path in an Undirected Tree
Given a tree as an adjacency list, return the sequence of nodes forming its diameter — the longest simple path between any two nodes.
Trees & GraphsBFSDFStree diameterpath reconstruction - Trees & GraphsHardAuto-gradedDetect a Profitable Currency Trade Loop
Tests whether you can model exchange rates as a weighted directed graph and apply Bellman-Ford to detect a cycle whose rate product exceeds 1.
Trees & Graphsgraphsbellman-fordlogarithms - Trees & GraphsMediumAuto-gradedReachable Stocked Nodes Within a Hop Limit
Tests BFS on an undirected graph to filter nodes by shortest-path distance and a secondary inventory condition, including edge-case handling for missing keys and duplicates.
Trees & Graphsbfsgraphsshortest-path - Trees & GraphsMediumAuto-gradedResolve Boolean Signal Chains with Negation and Cycle Detection
Tests iterative functional-graph traversal: propagating True/False through chains of references and NOT, while correctly marking cycles, dangling references, and their dependents as unresolvable.
Trees & Graphsgraph traversalcycle detectionhash map - Trees & GraphsMediumAuto-gradedExtract String Leaf Paths from Nested JSON Structure
Traverse nested dictionaries and lists to collect dot-and-bracket paths to all string values, returned in sorted order.
Trees & Graphstree-traversaliterationstackpath-building - Trees & GraphsMediumAuto-gradedGroup Serialized Tree Values by Depth
Parse a LeetCode-style level-order array and return values grouped into nested lists by depth, preserving left-to-right order.
Trees & Graphstreesbfsarrays - Trees & GraphsMediumAuto-gradedShared Manager in Organizational Hierarchy
Tests tree traversal, ancestor queries, and handling multiple input formats with a custom precedence rule.
Trees & Graphstreeslowest-common-ancestorgraph-traversal - Trees & GraphsMediumAuto-gradedFill Rooms With Distance to Nearest Exit
Tests multi-source BFS on a grid to propagate shortest walking distances from all exits simultaneously to every reachable empty room.
Trees & Graphsbfsgraphsgrid - Trees & GraphsMediumAuto-gradedRoot-to-Leaf Path Metrics on a Weighted Tree
Tests whether a candidate can traverse an unordered weighted tree in linear time to extract the root, the heaviest root-to-leaf path weight, and the maximum depth.
Trees & Graphstrees-graphshash-mapiterative-dfs - Trees & GraphsHardModel answerCheck Whether a Node Sequence Is a Valid BFS on a Tree
Given an undirected tree and multiple permutations of its nodes, determine for each permutation whether it could be the dequeue order of some BFS starting at its first element.
Trees & GraphsBFStreessimulationhashing - Trees & GraphsMediumModel answerHeight-Balanced Nodes in Heap-Array Trees
Traverse a binary tree stored in heap-index layout to find every node whose subtree is height-balanced, returning each with its tree level.
Trees & Graphsbinary-treepost-orderheap-layoutbottom-up - Trees & GraphsMediumAuto-gradedPlace One Beacon to Minimize Peak Shadow Distance
Tests binary search on a monotone feasibility predicate combined with multi-source BFS and Chebyshev distance geometry on a 2-D grid.
Trees & Graphsbfsbinary-searchgrid - Trees & GraphsMediumAuto-gradedRecursive Region Tree and Safe Graph Nodes
Tests recursive spatial subdivision (quadtree construction) and graph cycle detection (identifying nodes that always terminate).
Trees & Graphsrecursiongraphsdivide-and-conquertopological-sort - Trees & GraphsMediumAuto-gradedConvert Nested Dictionary to Dot-Separated Keys
Tests ability to traverse nested data structures and transform hierarchical key-value pairs into a flat representation using path notation.
Trees & Graphsrecursioniterationdictionarytree-traversal - Trees & GraphsMediumModel answerNearest Depot and Peak-Load Routing on a Grid
Given a grid with depot cells, find shortest paths from query locations to any depot, then extend to pick the depot maximizing a distance-penalized load score.
Trees & GraphsBFSDijkstramulti-sourcegrid - Trees & GraphsMediumAuto-gradedColumn-Ordered Tree Values From a Level-Order Array
Bucket level-order tree nodes by column, then sort each column by depth and value to produce the grouped output.
Trees & Graphsbinary-treebreadth-first-searchsortinghash-map - Trees & GraphsMediumAuto-gradedLargest Label Spread Across Graph Clusters
Tests ability to find connected components in an undirected graph and compute the maximum difference between the highest and lowest node labels in any single component.
Trees & Graphsunion-findgraphsconnected-components - Trees & GraphsHardAuto-gradedShortest Supplier Chain Between Two Vendors
Tests BFS-based shortest-path traversal on an undirected graph, including path reconstruction and degree-of-separation counting with correct edge-case handling.
Trees & GraphsgraphsBFSshortest-path - Trees & GraphsMediumModel answerPropagating Allow/Deny Permissions Through an Inheritance DAG
Given a DAG where each node carries allow and deny lists, compute every node's effective permissions by inheriting and merging rules along edges in topological order.
Trees & Graphsgraphstopological-sortpermissionsDAG - Trees & GraphsMediumModel answerRebuild a Binary Tree from Pre- and In-Order Sequences
Given preorder and inorder traversal arrays of a binary tree with unique values, reconstruct the tree in O(n) time and O(n) space.
Trees & Graphsbinary-treerecursionhash-maptraversal - Trees & GraphsMediumModel answerClosest Shared Ancestor for a Group of Org-Chart Nodes
Build a validated org-chart tree from manager–report pairs and find the deepest node that is an ancestor of every node in a given set.
Trees & Graphslowest-common-ancestorbinary-liftingtree-traversalinput-validation - Trees & GraphsMediumModel answerChain All Words Into One String via Shared Letters
Given a list of words, merge them into one string by joining where each word's last letter matches the next word's first letter, dropping the duplicate.
Trees & Graphseulerian-pathgraphstringshierholzer - Trees & GraphsMediumAuto-gradedConnected Land Regions on a Grid (8-Direction)
Tests graph traversal skills by counting connected components in a character grid where land cells are neighbours in all eight directions including diagonals.
Trees & Graphsgraph traversalBFS/DFSflood fillconnected components