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 361–390 of 434 results
Tests BFS on filtered graphs and Dijkstra with lexicographic two-criteria cost to navigate networks while minimizing hazardous-node visits then total hops.
Auto-gradedbfsdijkstrashortest-pathTests whether a candidate can reconstruct a unique binary tree from its preorder and inorder sequences and serialize the result breadth-first with null markers.
Auto-gradedbinary-treetraversalBFSiterativeImplement six independent algorithm problems covering BST operations, tree traversals, optimization, and graph exploration with correctness and complexity analysis.
Model answerbinary-treesbinary-search-treesgraph-traversaloptimizationTests graph traversal with cycle detection to compute a valid installation sequence for packages with dependencies.
Auto-gradedgraph-traversaltopological-sortcycle-detectiondfsModels discrete-time epidemic propagation on a grid where cells require multiple infected neighbors to catch the virus and recover after a fixed duration.
Auto-gradedsimulationbfsgraph-traversalExplore an unmapped grid using a restricted movement API to find a target location, tracking state through relative coordinates.
Model answergraph-traversaldfsstate-trackingbacktrackingTests iterative 2D graph traversal to count connected components of land cells without modifying the input or risking recursion stack overflow.
Auto-gradedgraph traversalBFS/DFSconnected componentsgridBuild a management structure from employee records, then count independent hierarchies, display staff by organizational depth, and locate shared supervisors.
Model answertree-constructionlevel-order-traversallowest-common-ancestorgraph-fundamentalsTests hierarchical hashing, tree traversal, and efficient change detection across nested directory structures
Auto-gradedhashingtree-traversaldiff-algorithmsTests grid connected-component labeling and the ability to optimally merge adjacent island regions by flipping a single water cell to land.
Auto-gradedgraphbfs-dfsconnected-componentsgridTests topological sorting with lexicographic tie-breaking and cycle detection in a directed graph.
Auto-gradedtopological-sortgraphheapcycle-detectionParse assignment statements and compute a variable's value by recursively resolving dependencies, detecting cycles and undefined references.
Model answerrecursiongraphsparsingdfsTests dependency graph traversal, cycle detection, and recursive evaluation of variables defined by arithmetic expressions.
Auto-gradedrecursiongraph-traversalcycle-detectionparsingFind the fewest cells to remove from a grid to prevent infection from spreading to healthy neighbors.
Model answerbipartite-matchinggraph-theorygridvertex-coverGiven a list of sponsor–member pairs, return the direct and full downstream unique reach count for every user, handling duplicates, converging paths, and cycles.
Model answergraphsBFSreachabilitycyclesTests Union-Find data structure application to track dynamic graph connectivity and determine when all nodes merge into one component.
Auto-gradedunion-finddisjoint-setgraph-connectivityTests BFS shortest path on a grid where state must encode both position and the set of collected keys, requiring multi-dimensional state space exploration.
Auto-gradedgraphsbfsgridbitmaskOrder tagged fragments so each fragment's ending tag matches the next fragment's starting tag, then concatenate their payloads into a single output string.
Model answergraphsstring-manipulationgraph-traversalTests flood-fill traversal to identify connected components in a 2D grid with four-directional adjacency.
Auto-gradedgraphsbfsdfsconnected-componentsTests binary tree traversal using an explicit stack to visit nodes in left-root-right sequence from a level-order serialized input.
Auto-gradedbinary-treetraversalstackdeserializationTests graph maintenance with dynamic edge insertion and deletion, proper handling of duplicates and missing edges, and final degree counting.
Auto-gradedgraphshash-tablesimulationTests tree traversal with state tracking to identify the shortest valid path satisfying a sum condition.
Auto-gradedbinary-treedfspath-findingTests understanding of multi-source BFS to compute the longest shortest path from any source to all required destinations on a grid with obstacles.
Auto-gradedbreadth-first-searchgridmulti-source-bfsshortest-pathFind the cheapest path through a cost-weighted grid containing impassable walls, returning the total cost and route, or -1 if no path exists.
Model answerdijkstrapriority-queueshortest-pathgridFinding the deepest node that lies on the upward path to the root for all given employees in a tree structure.
Auto-gradedtreelowest-common-ancestordepth-first-searchbreadth-first-searchGiven users and a chronological log of pairwise interactions, determine when everyone first becomes transitively connected through interaction chains.
Model answerunion-findgraph-connectivitytemporal-graphdisjoint-setVerify configuration integrity using polynomial hashing, detect dependency cycles with DFS, and produce a lexicographically-ordered topological deployment sequence.
Auto-gradedgraph-traversaltopological-sorthashingcycle-detectionTests ability to construct a deterministic frequency tree with tie-breaking, generate prefix-free binary codes, and encode/decode strings.
Auto-gradedtreesheapsgreedybit-manipulationTests bottom-up aggregation in trees represented as parent arrays, requiring iterative traversal to avoid recursion limits on deep trees.
Auto-gradedtreespost-orderaggregationiterativeMove n disks from one peg to another using a spare peg, one at a time, never placing a larger disk on a smaller one.
Model answerrecursionalgorithm-designcomplexity-analysis