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 211–240 of 434 results
Build an AST for variables, lambdas and applications, then infer each expression's most general function type using unification, with an occurs check to reject infinite types.
Model answertype-inferenceunificationhindley-milnerastFind the number of links on the path between two people in a company tree given as pairs, which tests undirected graph modeling and BFS or lowest common ancestor reasoning.
Auto-gradedgraphbfstreeshortest-pathEach tree node is an isolated process with only async send and blocking receive. Design a protocol so the root learns the tree size, tolerates lost and duplicate messages, and returns a structured result.
Model answerdistributed-systemsconvergecastidempotencyretriesFind every dictionary word that can be traced through orthogonally adjacent cells of a letter board without reusing a cell, using backtracking guided by a prefix tree.
Auto-gradedbacktrackingtriedfsgridCompute, for every open cell of a grid with walls and exits, the shortest 4-directional distance to any exit using multi-source BFS, leaving unreachable cells unchanged.
Auto-gradedbfsgridmulti-source-bfsmatrixFilter a service inventory by namespace, attributes and status, then compute transitive dependencies and risk flags from a root service, handling cycles and dangling references.
Auto-gradedgraph-traversaldfshash-mapfilteringRun BFS on a character grid to return the shortest move sequence to any exit, breaking ties by a fixed U, D, L, R direction priority.
Auto-gradedbfsgridshortest-pathpath-reconstructionFind connected components in a signed grid and pick the best-scoring one, with and without a no-negatives rule, reporting its first and last row-major cells.
Auto-gradedgriddfsconnected-componentstie-breakingSum durations over each root's subtree in a parent-linked record list and return the root with the largest total, testing tree aggregation and iterative traversal.
Auto-gradedtreedfshash-mapiterative-traversalFind the largest product of edge weights over simple directed paths between two nodes, using backtracking DFS, with a special case for identical endpoints and an unreachable case.
Auto-gradedgraphdfsbacktrackingsimple-pathsCompute each node's final letter set in a DAG where grants flow to all descendants but revocations apply only to the node that declares them.
Auto-gradedgraphdagtopological-sortbitmaskAnswer many ratio queries between named quantities from pairwise ratio facts, using a weighted union-find or component precomputation instead of a search per query.
Auto-gradedunion-findgraphweighted-union-findbatch-queriesModel one-way blast reach as a directed graph and find the largest set reachable from any single starting node, using exact integer distance checks.
Auto-gradedgraphdfsreachabilitygeometryRun a breadth-first search over (location, keys held) states in a forest with locked doors to find the first exit reached, or None.
Auto-gradedbfsgraphstate-space-searchparsingProject a heap-indexed binary tree onto a depth-by-column grid, then use BFS over non-zero cells to decide whether a cell holding the target is reachable from a given start.
Auto-gradedbinary-treebfsgridvertical-orderSimulate a mini spreadsheet where formulas are evaluated at write time, dependents update eagerly, and any write that would create a dependency cycle is rejected without changing state.
Auto-gradeddependency graphtopological sortcycle detectionsimulationBuild an independent deep copy of a nested container structure, preserving shared references and cycles, using a memo table and an explicit stack.
Auto-gradeddeep-copygraph-traversalmemoizationiterative-dfsWrite a crawler that explores a maze of HTTP endpoints to find the exit, coping with cycles, transient 503 errors and malformed JSON, while guaranteeing termination.
Model answergraph-traversalbfshttpretriesApply a Minesweeper-style tap to a grid, expanding through zero-mine regions with breadth-first search and labeling cells with adjacent mine counts.
Auto-gradedbfsgridmatrixsimulationCompute, for every cell of a grid, the fewest orthogonal steps to the closest marked cell, using a single multi-source breadth-first search; -1 everywhere when no cell is marked.
Auto-gradedbfsmulti-source-bfsgridshortest-pathBuild a bidirectional weighted graph from exchange rates and answer conversion queries with a deterministic BFS that multiplies rates along the first-found path, or -1.0 if none exists.
Auto-gradedgraphbfsweighted-graphhash-mapBacktracking over placements of named items on a grid under pairwise relative-position clues, deciding whether the target ends up in one cell across all valid layouts.
Auto-gradedbacktrackingconstraint-satisfactiongridsearchCombine topological ordering to find the minimum number of semesters (or detect a cycle) with a deque-based simulation of a two-rule request throttle that reports dropped timestamps.
Auto-gradedtopological-sortgraphcycle-detectionsliding-windowBuild a crawler that explores every page reachable from a seed URL using a slow, flaky link API, evolving from a sequential traversal to a thread pool with bounded, backoff-driven retries.
Model answerweb-crawlerconcurrencybfsretriesCount 4-connected land regions in a grid, then report the updated region count after each cell is converted from water to land, using incremental connectivity.
Auto-gradedunion-findgridconnected-componentsincremental-updatesCollect every page reachable from a seed URL on the same host, ignoring URL fragments and fetching each page once, first with one thread and then with safe concurrency.
Model answerweb-crawlerbfsconcurrencythread-safetyTurn manager rows into a tree, infer the root, print it with depth-based dot indentation, or list every (manager, employee) pair exactly two levels apart.
Model answertreepreorderiterative-dfshash-mapCompute the minimum cost to rewrite one string into another with directed priced letter swaps, using shortest paths over 26 letters and handling impossible positions and large totals.
Auto-gradedgraphfloyd-warshallshortest-pathstringsRun BFS on a link graph to find the lexicographically smallest fewest-hop route, where some pages fail a set number of times before their links load.
Auto-gradedbfsgraphshortest-pathretriesCount ordered 4-vertex walks along edges in an undirected graph whose vertices carry one of four labels, where each walk uses every label exactly once.
Auto-gradedgraphcountingcombinatoricsadjacency-list