KatInterview

practice a little every day — you've got this ♡

Trees & Graphs Interview Problems

Practice 5969 original coding, SQL, system design, machine learning and behavioral problems across 15 topics. Coding and SQL problems run against hidden test cases right in your browser; every problem has hints and a worked solution, free.

5969
Problems
2211
Auto-graded
15
Topics
272
Added today

Showing 331–349 of 349 results

  • Trees & GraphsHardAuto-graded
    Fastest Delivery Route with Fuel Station Stops

    Tests the ability to extend Dijkstra's algorithm with a constrained resource (fuel), requiring candidates to track both position and remaining fuel as state.

    Trees & Graphsgraphsdijkstrashortest pathdynamic programming
  • Trees & GraphsMediumAuto-graded
    Identify Connected Power Grid Regions

    Tests union-find (disjoint set union) to group transmission lines into connected components and answer queries about grid connectivity.

    Trees & Graphsunion-findgraphsconnected-components
  • Trees & GraphsMediumAuto-graded
    Greenhouse Disease Spread Timer

    Tests multi-source BFS to find the time until a grid-based propagation process completes or determine impossibility.

    Trees & Graphsbreadth-first-searchgridmulti-source-bfs
  • Trees & GraphsMediumAuto-graded
    Find All Downstream Dependents in a Dependency Graph

    Tests graph traversal with edge reversal to find all nodes reachable through reversed dependency edges, handling cycles correctly.

    Trees & Graphsgraph-traversalbfsdirected-graphcycle-detection
  • Trees & GraphsMediumAuto-graded
    Find Build Order With Optional Priorities

    Tests whether a candidate can produce a valid topological ordering of task dependencies while breaking ties by smallest task ID for determinism.

    Trees & Graphsgraphstopological sortBFSKahn's algorithm
  • Trees & GraphsMediumAuto-graded
    Maximum Path Gain in a Weighted Tree

    Tests tree DP on a weighted tree to find the maximum sum of node values along any root-to-leaf path, using depth-first traversal and subproblem combination.

    Trees & Graphstreesdynamic programmingdepth-first search
  • Trees & GraphsMediumAuto-graded
    Detect a Cycle in a Directed Course Prerequisite Graph

    Tests whether you can model dependency constraints as a directed graph and use topological sort to detect cycles that make all tasks impossible to complete.

    Trees & Graphstopological-sortgraphcycle-detection
  • Trees & GraphsHardAuto-graded
    Combine Tree Structures with Ordered Name Matching

    Tests recursive tree traversal with order-sensitive child pairing by name occurrence and careful handling of unmatched nodes.

    Trees & Graphsrecursiontree-traversalhash-table
  • Trees & GraphsMediumAuto-graded
    Connected Land Regions in a Character Matrix

    Tests graph traversal and connected-component identification on a 2D grid using flood-fill techniques.

    Trees & Graphsgraph-traversaldfsconnected-componentsgrid
  • Trees & GraphsMediumAuto-graded
    Detect Circular Dependencies in a Build System

    Tests cycle detection in a directed graph by determining which packages in a build dependency graph are part of a circular dependency chain.

    Trees & Graphsgraphscycle detectionDFStopological sort
  • Trees & GraphsMediumAuto-graded
    Minimum Build Phases for a Software Dependency Graph

    Tests whether a candidate can apply topological ordering (Kahn's algorithm / BFS layer-by-layer) to schedule tasks into the fewest sequential build phases.

    Trees & Graphsgraphstopological sortBFSDAG
  • Trees & GraphsMediumAuto-graded
    Schedule Dependent Tasks with Priority and Tag Exclusion

    Tests Kahn's algorithm with deterministic tie-breaking, urgency-based heap ordering, cycle detection with path reporting, and transparent skipping of tag-excluded tasks.

    Trees & Graphstopological-sortheapgraphs
  • Trees & GraphsMediumAuto-graded
    Sum of Decimal Paths in a Binary Tree

    Tests depth-first (or breadth-first) traversal of a binary tree while tracking the accumulated digit value along each root-to-leaf path.

    Trees & Graphsbinary-treebfsdfs
  • Trees & GraphsMediumAuto-graded
    Recover Build Order From Incremental Patch Dependencies

    Tests whether candidates can apply topological sort (Kahn's algorithm or DFS) to determine a valid linear build order from a dependency graph of software patches.

    Trees & Graphsgraphstopological sortBFSKahn's algorithm
  • Trees & GraphsHardAuto-graded
    Minimum Batches to Complete All Courses with Prerequisites

    Tests topological ordering (Kahn's algorithm / BFS layering) to schedule dependent courses into the fewest sequential batches where each batch runs in parallel.

    Trees & Graphsgraphstopological-sortBFS
  • Trees & GraphsEasyAuto-graded
    Maximum Sum of Independent Nodes in a Tree

    Tests tree DP by finding the maximum sum of node values when no two selected nodes may be adjacent (parent-child) in a rooted tree.

    Trees & Graphstreedynamic programmingrecursion
  • Trees & GraphsMediumAuto-graded
    Minimum Steps to Collect All Treasure on a Grid

    Tests BFS shortest-path reasoning on a grid by finding the minimum steps to collect all treasure chests from a starting position, visiting each chest at least once.

    Trees & GraphsgraphsBFSgridshortest path
  • Trees & GraphsHardAuto-graded
    Fastest Delivery Route with Fuel Stop Limit

    Tests the ability to apply Dijkstra's algorithm augmented with a constraint dimension (fuel stops used) to find the minimum-time path in a weighted graph.

    Trees & Graphsgraphsdijkstrashortest pathdynamic programming
  • Trees & GraphsHardAuto-graded
    Shortest Evacuation Route Through a Burning Building

    Tests BFS shortest-path reasoning on a grid with time-dependent obstacles, requiring candidates to track fire spread and find the minimum escape steps simultaneously.

    Trees & Graphsbfsgridshortest pathmulti-source bfs