practice a little every day — you've got this ♡
Trees & Graphs Interview Problems
Practice 5967 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.
- 5967
- Problems
- 2210
- Auto-graded
- 15
- Topics
- 272
- Added today
Showing 61–85 of 85 results
- 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 & GraphsMediumModel answerMinimum Arrival Time in a Scheduled Transit Network
Find the earliest time a traveler can reach a destination station given a fixed train timetable, then reconstruct the full itinerary with transfers and waits.
Trees & Graphsgraph-searchdijkstrabfstime-expanded-graph - Trees & GraphsEasyModel answerPath Sum Validation in Binary Trees
Determine whether any root-to-leaf path in a binary tree sums to a given target value.
Trees & Graphsbinary-treedepth-first-searchtree-traversal - Trees & GraphsMediumModel answerCluster Exposures: Net Change per Asset Group
Find connected components in an asset correlation graph and return the summed position delta for each component as a labeled group.
Trees & Graphsgraph traversalconnected componentshash mapDFS - Trees & GraphsMediumModel answerAssemble a Binary Tree from Parent-Child Edge Records
Given a list of directed labeled edges, reconstruct the binary tree they describe and return its root node.
Trees & Graphsbinary-treehash-maptree-construction - Trees & GraphsMediumModel answerSearch and Shortest-Path Algorithms
Implement binary search on a monotone predicate, BFS for state-space and grid shortest paths, and random board generation with adjacency counting.
Trees & Graphsbinary-searchbfsshortest-pathgraph-traversal - Trees & GraphsHardModel answerLogical Inference Engine: TRUE, FALSE, or Undetermined
Build a function that classifies propositions as definitely true, definitely false, or undetermined given a set of facts and implication rules.
Trees & Graphsgraphimplication2-SATDFS - Trees & GraphsMediumModel answerRobot Grid Exploration with Limited Sensing API
Navigate a robot through an unmapped grid with obstacles using only movement and turn commands to locate a target cell.
Trees & Graphsdfsbacktrackinggraph-traversalsimulation - Trees & GraphsHardModel answerShortest Path for a Hobbled Xiangqi Horse on a 10×9 Board
Find the minimum moves for a Chinese-chess horse to reach a target on a 10×9 grid, accounting for the leg-blocking movement restriction and obstacle squares.
Trees & GraphsBFSgraph traversalboard gamesshortest path - Trees & GraphsMediumModel answerRecursive Maximum Search in an Arbitrary Binary Tree
Write a recursive function that traverses a binary tree to locate the largest integer value, accounting for null pointers and negative-only trees.
Trees & Graphsrecursionbinary-treetraversaledge-cases - Trees & GraphsMediumModel answerMulti-Problem Algorithm Sprint: Trees, Grids, and Heaps
Implement six independent algorithm problems covering BST operations, tree traversals, optimization, and graph exploration with correctness and complexity analysis.
Trees & Graphsbinary-treesbinary-search-treesgraph-traversaloptimization - Trees & GraphsMediumModel answerMaze Exploration with Limited Sensor API
Explore an unmapped grid using a restricted movement API to find a target location, tracking state through relative coordinates.
Trees & Graphsgraph-traversaldfsstate-trackingbacktracking - Trees & GraphsMediumModel answerEmployee Hierarchy: Counting Trees, Level Traversal, and Ancestor Search
Build a management structure from employee records, then count independent hierarchies, display staff by organizational depth, and locate shared supervisors.
Trees & Graphstree-constructionlevel-order-traversallowest-common-ancestorgraph-fundamentals - Trees & GraphsMediumModel answerResolve Variable Assignments with Dependencies
Parse assignment statements and compute a variable's value by recursively resolving dependencies, detecting cycles and undefined references.
Trees & Graphsrecursiongraphsparsingdfs - Trees & GraphsMediumModel answerGrid Containment: Minimum Removals to Stop Spread
Find the fewest cells to remove from a grid to prevent infection from spreading to healthy neighbors.
Trees & Graphsbipartite-matchinggraph-theorygridvertex-cover - Trees & GraphsMediumModel answerCompute Direct and Total Network Reach for Each User
Given a list of sponsor–member pairs, return the direct and full downstream unique reach count for every user, handling duplicates, converging paths, and cycles.
Trees & GraphsgraphsBFSreachabilitycycles - Trees & GraphsMediumModel answerChain Fragment Payloads by Matching Tags
Order tagged fragments so each fragment's ending tag matches the next fragment's starting tag, then concatenate their payloads into a single output string.
Trees & Graphsgraphsstring-manipulationgraph-traversal - Trees & GraphsMediumModel answerWeighted Grid Navigation: Minimum Cost Path Around Walls
Find the cheapest path through a cost-weighted grid containing impassable walls, returning the total cost and route, or -1 if no path exists.
Trees & Graphsdijkstrapriority-queueshortest-pathgrid - Trees & GraphsMediumModel answerTimestamp When All Users Form a Single Connected Group
Given users and a chronological log of pairwise interactions, determine when everyone first becomes transitively connected through interaction chains.
Trees & Graphsunion-findgraph-connectivitytemporal-graphdisjoint-set - Trees & GraphsMediumModel answerRecursive Disk Transfer Between Three Pegs
Move n disks from one peg to another using a spare peg, one at a time, never placing a larger disk on a smaller one.
Trees & Graphsrecursionalgorithm-designcomplexity-analysis - Trees & GraphsHardModel answerNavigate Between Nodes in a Recursively Defined Binary Tree
Determine the path between two nodes in a Fibonacci-style binary tree using only their preorder indices, without building the tree in memory.
Trees & Graphsbinary-treesrecursionfibonaccitree-traversal - Trees & GraphsMediumModel answerBuild a Same-Domain Web Page Crawler
Write a crawler that visits all pages reachable from a start URL, staying within the same domain, avoiding cycles and duplicate fetches.
Trees & Graphsgraph-traversalbfsdfsurl-parsing - Trees & GraphsMediumModel answerBuild a File Owner Aggregator for Code Review Assignment
Parse Git diffs and a CSV ownership map to identify which contributor owns the most modified files in a branch comparison.
Trees & Graphsgitfile-iocsvaggregation - Trees & GraphsMediumModel answerFinding Profitable Exchange Cycles with Transaction Fees
Given exchange rates between currencies and a per-cycle transaction cost, determine if any sequence of trades can yield a profit.
Trees & Graphsgraph-algorithmsbellman-fordnegative-cyclelogarithms