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 241–270 of 434 results
Find the minimum time to complete all tasks with durations and prerequisites under unlimited parallelism, or detect a circular dependency, using longest path in a DAG with topological ordering.
Auto-gradedtopological-sortgraphdaglongest-pathCount the directed edges of a tree that point toward a chosen root, which is the minimum number of flips needed to orient every edge away from it.
Auto-gradedtreegraph-traversaldfsbfsCompute when each grid cell becomes infected under a synchronous neighbor-count rule, using a multi-source BFS that updates counts incrementally instead of rescanning each round.
Auto-gradedbfsgridsimulationmulti-source-bfsGiven a level-order serialized binary tree, return the first and last node value at each depth, testing BFS over an array-encoded tree and careful handling of null slots.
Auto-gradedbinary-treebfslevel-orderserializationFind the longest path, counted in edges, between any two nodes of a binary tree stored as a child-index list, testing tree height computation and avoiding deep recursion.
Auto-gradedbinary-treedfsbfstree-heightRebuild a binary search tree from its preorder listing of distinct integers in linear time, then report it in level order with null placeholders. Tests stack-based construction and BFS serialization.
Auto-gradedbinary-search-treestackpreorderbfsImplement a thread-safe crawler that explores links from a seed page to a given depth, never fetches a URL twice, and caps the number of simultaneous fetches.
Model answerconcurrencybfsthread-poolgraph-traversalMerge two keyed n-ary trees by summing values, encode them canonically, and strictly parse an encoded string with validation.
Auto-gradedtreerecursionparsingserializationDefine a text format for ordered trees with arbitrary branching, then write an encoder and decoder that rebuild the exact same values, structure and child order in linear time.
Model answertreeserializationn-ary-treeiterative-dfsProduce the lexicographically smallest topological ordering of a dependency graph, or an empty list if the dependencies contain a cycle.
Auto-gradedtopological-sortgraphheapcycle-detectionTransform a tree of Scan, Filter, Project and Join operators by moving filters toward the leaves and removing unused columns, while keeping query results unchanged.
Model answertree-rewritingquery-optimizationpredicate-pushdownprojection-pruningCompute the fewest +1 increments that make every root-to-leaf path total equal in a large rooted tree given as a parent array, which needs a bottom-up greedy and an iterative traversal.
Auto-gradedtreegreedybfstree-dpBuild a valid course order from prerequisite pairs while skipping passed courses, using a topological sort with a fixed tie-break order and cycle detection.
Auto-gradedtopological-sortgraphbfscycle-detectionUse recursion and backtracking to enumerate every ordered move sequence on a 4×4 board where three consecutive marks (not four) wins.
Model answerbacktrackingrecursiongame-treecombinatoricsTests in-order traversal of a binary search tree encoded in parallel arrays, with early termination and iterative stack management.
Auto-gradedbinary-search-treein-order-traversaliterativestackTests grid-based connected-components detection using flood-fill or DFS, covering neighbor connectivity, visited-state tracking, and iterative traversal.
Auto-gradedgraphsgriddfsconnected-componentsTests recursive AST traversal by simplifying an arithmetic expression tree through constant folding and algebraic identity rules, including cascading rewrites.
Auto-gradedtreesrecursionastBuild a weighted graph from currency pairs and answer conversion queries, then extend to directional rates and arbitrage detection.
Model answergraph-traversalshortest-pathbellman-fordfloating-pointTests recursive-free N-ary tree traversal and set-based diffing to count nodes added, removed, or modified between two tree snapshots.
Auto-gradedtreeshashingtraversalTests two skills at once: directional obstacle scanning on a 2D grid, and bitmask-based palindrome counting over rooted-tree ancestor segments.
Auto-gradedgridbit-manipulationdfsFind how many steps a contamination spreads from multiple sources through a grid, or determine if some cells remain permanently unaffected.
Model answerBFSmulti-source BFSgrid traversalshortest pathTests bottom-up tree traversal with greedy balancing, recognizing that shared ancestors minimize total increments across multiple paths.
Auto-gradedbinary-treegreedypost-order-traversaltree-dpDecide whether a word can be spelled by a non-repeating, four-directional path of adjacent cells in a character matrix, with pruning and complexity analysis.
Model answerbacktrackingdepth-first-searchgridpruningTests ability to model a 2D grid as an unweighted graph and apply BFS to find the fewest moves between two corners while avoiding walls.
Auto-gradedbfsgraphsgridTests iterative graph traversal (DFS/BFS) on a binary grid, including bounds handling, visited-marking strategy, and complexity analysis.
Auto-gradedgraph traversalDFSBFSmatrixTests whether a candidate can find the minimax-cost path in a filtered graph, recognising that one edge attribute gates inclusion while another drives the optimisation.
Auto-gradedgraphdijkstraminimaxshortest-pathDesign and code a React component that displays hierarchical data with interactive expand/collapse behavior and full keyboard accessibility.
Model answerreactrecursionaccessibilitystate-managementTests topological processing of a DAG where each node computes an active letter set from its parents' resolved sets plus its own additions and removals.
Auto-gradedtopological-sortbit-manipulationgraphTests BFS-based grid traversal by counting distinct empty cells reachable from a starting position within a fixed number of 8-directional moves.
Auto-gradedbfsgridgraph-traversalTests your ability to perform pre-order depth-first traversal on a tree structure and track hierarchical depth for each node.
Auto-gradedtree-traversaldfsdepth-tracking