practice a little every day — you've got this ♡
Trees & Graphs Interview Problems
Practice 5974 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.
- 5974
- Problems
- 2212
- Auto-graded
- 15
- Topics
- 269
- Added today
Showing 301–330 of 434 results
- Trees & GraphsMediumAuto-gradedGroup Accounts by Shared Identity Fields
Tests the ability to model transitive relationships between records using Union-Find (DSU) to identify connected components linked by shared attribute values.
Trees & Graphsunion-findconnected-componentshashing - 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 & GraphsMediumAuto-gradedFind the Hub Node in a Star-Shaped Network
Tests recognition of star-graph topology and the insight that the central node is uniquely identified by its degree.
Trees & Graphsgraphsdegreestar-graph - Trees & GraphsMediumAuto-gradedFind the Bottleneck Weight Between Two Nodes
Compute the smallest possible maximum edge weight along any path connecting two vertices in a weighted undirected graph.
Trees & Graphsgraphunion-findgreedybottleneck-path - Trees & GraphsMediumAuto-gradedShortest Path from Multiple Sources in a Grid
Tests understanding of multi-source BFS to efficiently compute shortest distances from any of several starting points to many query locations.
Trees & Graphsbfsgraph-traversalshortest-pathgrid - Trees & GraphsMediumAuto-gradedSpot the VIP in a Social Network
Tests whether a candidate can exploit a single elimination insight to find a universal acquaintance in O(n) time instead of O(n²).
Trees & Graphsgraphseliminationtwo-pass - Trees & GraphsMediumAuto-gradedMinimum Travel Cost with Layover Limit
Tests weighted shortest-path reasoning under a hard constraint on the number of edges traversed, requiring a round-bounded relaxation strategy.
Trees & Graphsgraphsbellman-fordshortest-path - Trees & GraphsMediumAuto-gradedRoot-to-Leaf Sum Verification
Tests depth-first traversal of a binary tree encoded as an indexed array to find paths matching a target sum.
Trees & Graphsbinary-treedfsiterativepath-sum - Trees & GraphsMediumAuto-gradedGrid Maze Shortest Path with A* Search
Tests knowledge of informed graph search, admissible heuristics, priority-queue mechanics, and canonical path reconstruction on a 2-D grid.
Trees & Graphsgraph-searcha-starbfsshortest-path - 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 & GraphsMediumAuto-gradedSchedule Courses Given Prerequisites
Tests directed graph modeling, cycle detection, and topological ordering using Kahn's algorithm or DFS.
Trees & Graphstopological-sortgraphkahn-algorithmcycle-detection - Trees & GraphsMediumAuto-gradedCompute Reporting Metrics in a Company Hierarchy
Tests tree construction from parent pointers and post-order traversal to aggregate counts across nested organizational levels.
Trees & Graphstreedfspost-orderrecursion - 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 & GraphsHardAuto-gradedSafe Edge Insertion Check for a Dependency Graph
Tests graph reachability and cycle detection: determine whether a new directed edge can be added to an acyclic dependency graph without introducing a cycle.
Trees & Graphsgraphsdepth-first-searchcycle-detectionreachability - Trees & GraphsMediumAuto-gradedShortest Route Through a Blocked Matrix
Find the minimum number of unit moves from the top-left to the bottom-right cell of a 0/1 matrix, or report that no route exists.
Trees & Graphsbfsgridshortest-pathgraph-traversal - Trees & GraphsHardAuto-gradedMinimum Time to Complete All Build Tasks with Dependencies
Tests ability to apply topological ordering (Kahn's algorithm) to schedule parallel tasks with durations and prerequisite chains, computing the earliest completion time.
Trees & Graphsgraphstopological sortdynamic programmingBFS - 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 & GraphsMediumAuto-gradedGrid Land Regions: Total Count and Unique Footprints
Tests grid flood-fill for connected-component counting and translation-invariant shape canonicalization to identify structurally distinct land regions.
Trees & Graphsgraph traversalflood fillconnected componentshashing - Trees & GraphsMediumAuto-gradedMinimum-Cost Flight Path with Departure Window
Tests constrained graph search: find the cheapest multi-leg flight route where only the first leg must depart within a given date range, connections must respect time ordering, and cycles are forbidden.
Trees & Graphsdijkstragraphsshortest-path - Trees & GraphsMediumAuto-gradedMutual Connections: Find Shared Friends from Follow Data
Tests graph reciprocity reasoning and set intersection: given directed follow edges, identify all users who are mutual friends with both members of every user pair.
Trees & Graphsgraphsset-intersectionsocial-network - Trees & GraphsEasyAuto-gradedShortcut by Adding Free Unit Edges
Reason about degrees of freedom: since you may add arbitrary weight-1 edges, the optimal distance collapses to a constant.
Trees & Graphsgraphsshortest-pathreasoningedge-cases - Trees & GraphsMediumAuto-gradedMinimum Water Cells to Connect Two Land Masses
Tests ability to combine flood-fill island identification with multi-source BFS to find the shortest water path bridging two disconnected land regions in a grid.
Trees & Graphsbfsgridflood-fill - Trees & GraphsHardAuto-gradedFilter Hierarchical Records by Ancestor Validity
Tests memoized path traversal in a parent-pointer hierarchy with cycle detection and ancestral filtering rules.
Trees & Graphsgraphsmemoizationcycle-detection - Trees & GraphsMediumAuto-gradedAnswer Reachability Queries on an Undirected Graph
Build connected components from an edge list with Union-Find, then answer many connectivity queries quickly.
Trees & Graphsunion-findgraphdisjoint-setconnectivity - Trees & GraphsMediumAuto-gradedBest Meeting Point Across All Stations in a City Grid
Tests multi-source BFS on a grid to find the open cell with the smallest total shortest-path distance to every station, respecting walls and blocked cells.
Trees & Graphsbfsgridshortest-path - Trees & GraphsMediumAuto-gradedLongest Path in an Undirected Tree
Tests whether a candidate can find the longest edge-path in a tree using two linear-time traversals and reason about why the approach is correct.
Trees & Graphsbfstreesgraph-traversal - Trees & GraphsMediumAuto-gradedFewest Cells Through a Diagonal-Move Grid
Find the length of the shortest 8-directional clean-cell path across a square 0/1 grid using BFS.
Trees & Graphsbfsgridshortest-path - Trees & GraphsMediumAuto-gradedVirus Spread on a Grid
Tests multi-source BFS on a 2D grid to find the minimum number of rounds for an infection to reach every susceptible cell, or detect if it cannot.
Trees & Graphsbfsmatrixmulti-source - Trees & GraphsMediumAuto-gradedEarliest-Arrival Reachability on Timed Transit Routes
Tests whether a candidate can model time-respecting graph search over indexed transit routes to determine if a destination is reachable from a starting stop.
Trees & Graphsgraph searchBFSgreedyshortest path - Trees & GraphsMediumAuto-gradedCheapest Type Transformation Path
Tests shortest-path reasoning on a weighted directed graph, including source-caching strategy, zero-cost edges, unreachable nodes, and same-source queries.
Trees & Graphsgraphsshortest-pathdijkstra