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 91–120 of 434 results
Compute a conversion factor between two currencies by chaining and inverting listed rates, returning -1.0 when no chain exists; tests graph traversal with multiplicative weights.
Auto-gradedgraphbfshash-mapweighted-edgesFind the non-adjacent node in an undirected graph with the maximum count of shared neighbors relative to a target node.
Auto-gradedgraphsbfshash-tablesocial-networkCrawl a website graph from a start URL to an exit page using BFS, retrying transient 5xx failures a limited number of times, and return the minimum hop count or -1.
Model answerbfsgraph-traversalretry-logicvisited-setAggregate subtree salary totals and headcounts bottom-up in a tree given as a flat list, then pick the best root using exact average comparison with size and id tie-breaks.
Auto-gradedtreedfspost-ordertie-breakingFind the cheapest route on a grid with free, paid and blocked cells plus same-numbered teleport cells, which calls for 0-1 BFS and care with teleport expansion.
Auto-graded0-1 BFSshortest pathgridgraph modelingWalk a nested structure of dicts and lists depth-first and gather every value stored under a given key, in traversal order, including matches inside already-matched values.
Auto-gradedrecursiondfsjsontraversalConstruct a hierarchical forest from directed child-parent relations and output a depth-annotated preorder traversal.
Auto-gradedtrees-graphsdepth-first-searchstackrecursionFind the open cell with the smallest total shortest-path distance to a set of target cells on a grid with obstacles, using BFS and reachability counting.
Auto-gradedbfsgridshortest-pathgraph-traversalCompute the depth of a rooted tree given as a parent array after splicing out marked nodes, so their children attach to the nearest surviving ancestor.
Auto-gradedtreebfsparent-arraydepthFind the largest product of directed exchange rates along any path between two currencies, using Bellman-Ford-style relaxation on a graph that may contain cycles and rates above 1.
Auto-gradedgraphbellman-fordshortest-pathcurrencyDetermine whether empty grid plots can be assigned one of k colors without adjacent conflicts.
Auto-gradedtrees-graphsarraysmath-bitsSimulate multi-source BFS propagation across a 2D grid up to a maximum number of steps.
Auto-gradedbreadth-first-searchmatrixgraph-traversalDecide whether a string becomes a palindrome after removing at most one character, then group a binary tree's node values by column using level-order tie-breaking.
Model answertwo-pointerspalindromebfsbinary-treeCompute the shortest total time to finish all jobs with unlimited parallelism by finding the longest weighted path in a dependency graph, returning -1 if a cycle exists.
Auto-gradedtopological-sortdaglongest-pathdynamic-programmingConstruct the lexicographically smallest topological ordering of nodes in a forest defined by an ancestor/parent mapping.
Auto-gradedtrees-graphsheaps-sortinggreedy-intervalsTests modeling word edits as an implicit graph and running BFS with wildcard buckets to find the minimum number of one-letter changes, with careful edge cases.
Auto-gradedbfsgraphstringshashingCompute how many pebbles can be taken off a board when each removal needs another remaining pebble in the same row or column, using connected components.
Auto-gradedunion-findconnected-componentsgraph-modelingdfsCombine contact records that are directly or transitively linked by a shared email, outputting each person's name with a deduplicated, sorted email list.
Model answerunion-findgraphconnected-componentsdfsFind the longest simple path from a start node in a directed graph with possible cycles, using backtracking DFS with a per-path visited set.
Auto-gradedgraphdfsrecursionbacktrackingSolve five small tasks in one call: count graph components, minimum swaps to sort, largest monotonic number, simulate an LRU cache, and compare two N-ary trees.
Auto-gradedgraph-traversalcycle-decompositiongreedy-digitslru-cacheCount 4-directionally connected clusters of 1s in a binary matrix using graph traversal, with care for visited tracking, empty inputs, and deep clusters.
Auto-gradeddfsgridconnected-componentsmatrixBrute-force enumerate looping command scripts of length 1 to 10 and simulate each on a grid with fuel, walls and refuel pads, using state-repeat detection to stop loops.
Auto-gradedsimulationbrute-forcegridcycle-detectionParse an indentation-based, pipe-delimited menu into a nested tree of dictionaries, testing stack-based hierarchy reconstruction and careful field parsing.
Auto-gradedtree-constructionstackparsingstringsFind the value in a Binary Search Tree represented as a level-order array that has the smallest absolute difference to a target number.
Auto-gradedtrees-graphsbinary-search-treesearchCompute the minimum number of 4-directional moves between two open cells of a binary maze, or -1 if unreachable; tests breadth-first search on an implicit grid graph.
Auto-gradedbfsgridshortest-pathgraphGiven courses with durations, prerequisite links and a list of goal courses, compute the minimum time to finish the goals and their needed prerequisites, as total effort and as elapsed time.
Model answergraphtopological-sortdagcycle-detectionEvaluates tree properties, cycle detection, edge validity, and in-order traversal under strict error precedence.
Auto-gradedtreesgraphsdfstraversalTurn a flat batch of scheduler tasks into a display list: merge duplicates, hide finished work, order by priority, and keep each subtask right under its parent.
Model answersortinghashingtree-traversalcycle-detectionDesign a reliable message passing protocol across adjacent tree nodes, then compute total network size and discover paths under network faults.
Model answertrees-graphsdistributed-systemsmessage-passingnetwork-protocolTurn a set of contest-style logic puzzles, led by the fox-chicken-grain river crossing, into formal models, and give algorithms with proofs of correctness and optimality.
Model answerbfsstate-space-searchinvariantsproofs