Topic
Trees & Graphs interview problems
Traversals, shortest paths, topological order and union-find. 434 original problems, each with hidden test cases you can run in the browser.
25 easy362 medium47 hard
Showing 301–330 of 434 results
Tests the ability to model transitive relationships between records using Union-Find (DSU) to identify connected components linked by shared attribute values.
Auto-gradedunion-findconnected-componentshashingFind the earliest time a traveler can reach a destination station given a fixed train timetable, then reconstruct the full itinerary with transfers and waits.
Model answergraph-searchdijkstrabfstime-expanded-graphTests recognition of star-graph topology and the insight that the central node is uniquely identified by its degree.
Auto-gradedgraphsdegreestar-graphCompute the smallest possible maximum edge weight along any path connecting two vertices in a weighted undirected graph.
Auto-gradedgraphunion-findgreedybottleneck-pathTests understanding of multi-source BFS to efficiently compute shortest distances from any of several starting points to many query locations.
Auto-gradedbfsgraph-traversalshortest-pathgridTests whether a candidate can exploit a single elimination insight to find a universal acquaintance in O(n) time instead of O(n²).
Auto-gradedgraphseliminationtwo-passTests weighted shortest-path reasoning under a hard constraint on the number of edges traversed, requiring a round-bounded relaxation strategy.
Auto-gradedgraphsbellman-fordshortest-pathTests depth-first traversal of a binary tree encoded as an indexed array to find paths matching a target sum.
Auto-gradedbinary-treedfsiterativepath-sumTests knowledge of informed graph search, admissible heuristics, priority-queue mechanics, and canonical path reconstruction on a 2-D grid.
Auto-gradedgraph-searcha-starbfsshortest-pathDetermine whether any root-to-leaf path in a binary tree sums to a given target value.
Model answerbinary-treedepth-first-searchtree-traversalTests directed graph modeling, cycle detection, and topological ordering using Kahn's algorithm or DFS.
Auto-gradedtopological-sortgraphkahn-algorithmcycle-detectionTests tree construction from parent pointers and post-order traversal to aggregate counts across nested organizational levels.
Auto-gradedtreedfspost-orderrecursionFind connected components in an asset correlation graph and return the summed position delta for each component as a labeled group.
Model answergraph traversalconnected componentshash mapDFSTests graph reachability and cycle detection: determine whether a new directed edge can be added to an acyclic dependency graph without introducing a cycle.
Auto-gradedgraphsdepth-first-searchcycle-detectionreachabilityFind 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.
Auto-gradedbfsgridshortest-pathgraph-traversalTests ability to apply topological ordering (Kahn's algorithm) to schedule parallel tasks with durations and prerequisite chains, computing the earliest completion time.
Auto-gradedgraphstopological sortdynamic programmingBFSGiven a list of directed labeled edges, reconstruct the binary tree they describe and return its root node.
Model answerbinary-treehash-maptree-constructionTests grid flood-fill for connected-component counting and translation-invariant shape canonicalization to identify structurally distinct land regions.
Auto-gradedgraph traversalflood fillconnected componentshashingTests 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.
Auto-gradeddijkstragraphsshortest-pathTests graph reciprocity reasoning and set intersection: given directed follow edges, identify all users who are mutual friends with both members of every user pair.
Auto-gradedgraphsset-intersectionsocial-networkReason about degrees of freedom: since you may add arbitrary weight-1 edges, the optimal distance collapses to a constant.
Auto-gradedgraphsshortest-pathreasoningedge-casesTests 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.
Auto-gradedbfsgridflood-fillTests memoized path traversal in a parent-pointer hierarchy with cycle detection and ancestral filtering rules.
Auto-gradedgraphsmemoizationcycle-detectionBuild connected components from an edge list with Union-Find, then answer many connectivity queries quickly.
Auto-gradedunion-findgraphdisjoint-setconnectivityTests 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.
Auto-gradedbfsgridshortest-pathTests 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.
Auto-gradedbfstreesgraph-traversalFind the length of the shortest 8-directional clean-cell path across a square 0/1 grid using BFS.
Auto-gradedbfsgridshortest-path- Virus Spread on a GridMedium
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.
Auto-gradedbfsmatrixmulti-source 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.
Auto-gradedgraph searchBFSgreedyshortest pathTests shortest-path reasoning on a weighted directed graph, including source-caching strategy, zero-cost edges, unreachable nodes, and same-source queries.
Auto-gradedgraphsshortest-pathdijkstra