KatInterview

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

Trees & Graphs Interview Problems

Practice 5973 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.

5973
Problems
2212
Auto-graded
15
Topics
271
Added today

Showing 241–270 of 349 results

  • Trees & GraphsMediumAuto-graded
    Find the Bottleneck Weight Between Two Nodes

    Compute the smallest possible maximum edge weight along any path connecting two vertices in a weighted undirected graph.

    Trees & Graphsgraphunion-findgreedybottleneck-path
  • Trees & GraphsMediumAuto-graded
    Shortest Path from Multiple Sources in a Grid

    Tests understanding of multi-source BFS to efficiently compute shortest distances from any of several starting points to many query locations.

    Trees & Graphsbfsgraph-traversalshortest-pathgrid
  • Trees & GraphsMediumAuto-graded
    Spot the VIP in a Social Network

    Tests whether a candidate can exploit a single elimination insight to find a universal acquaintance in O(n) time instead of O(n²).

    Trees & Graphsgraphseliminationtwo-pass
  • Trees & GraphsMediumAuto-graded
    Minimum Travel Cost with Layover Limit

    Tests weighted shortest-path reasoning under a hard constraint on the number of edges traversed, requiring a round-bounded relaxation strategy.

    Trees & Graphsgraphsbellman-fordshortest-path
  • Trees & GraphsMediumAuto-graded
    Root-to-Leaf Sum Verification

    Tests depth-first traversal of a binary tree encoded as an indexed array to find paths matching a target sum.

    Trees & Graphsbinary-treedfsiterativepath-sum
  • Trees & GraphsMediumAuto-graded
    Grid Maze Shortest Path with A* Search

    Tests knowledge of informed graph search, admissible heuristics, priority-queue mechanics, and canonical path reconstruction on a 2-D grid.

    Trees & Graphsgraph-searcha-starbfsshortest-path
  • Trees & GraphsMediumAuto-graded
    Schedule Courses Given Prerequisites

    Tests directed graph modeling, cycle detection, and topological ordering using Kahn's algorithm or DFS.

    Trees & Graphstopological-sortgraphkahn-algorithmcycle-detection
  • Trees & GraphsMediumAuto-graded
    Compute Reporting Metrics in a Company Hierarchy

    Tests tree construction from parent pointers and post-order traversal to aggregate counts across nested organizational levels.

    Trees & Graphstreedfspost-orderrecursion
  • Trees & GraphsHardAuto-graded
    Safe Edge Insertion Check for a Dependency Graph

    Tests graph reachability and cycle detection: determine whether a new directed edge can be added to an acyclic dependency graph without introducing a cycle.

    Trees & Graphsgraphsdepth-first-searchcycle-detectionreachability
  • Trees & GraphsMediumAuto-graded
    Shortest Route Through a Blocked Matrix

    Find the minimum number of unit moves from the top-left to the bottom-right cell of a 0/1 matrix, or report that no route exists.

    Trees & Graphsbfsgridshortest-pathgraph-traversal
  • Trees & GraphsHardAuto-graded
    Minimum Time to Complete All Build Tasks with Dependencies

    Tests ability to apply topological ordering (Kahn's algorithm) to schedule parallel tasks with durations and prerequisite chains, computing the earliest completion time.

    Trees & Graphsgraphstopological sortdynamic programmingBFS
  • Trees & GraphsMediumAuto-graded
    Grid Land Regions: Total Count and Unique Footprints

    Tests grid flood-fill for connected-component counting and translation-invariant shape canonicalization to identify structurally distinct land regions.

    Trees & Graphsgraph traversalflood fillconnected componentshashing
  • Trees & GraphsMediumAuto-graded
    Minimum-Cost Flight Path with Departure Window

    Tests constrained graph search: find the cheapest multi-leg flight route where only the first leg must depart within a given date range, connections must respect time ordering, and cycles are forbidden.

    Trees & Graphsdijkstragraphsshortest-path
  • Trees & GraphsMediumAuto-graded
    Mutual Connections: Find Shared Friends from Follow Data

    Tests graph reciprocity reasoning and set intersection: given directed follow edges, identify all users who are mutual friends with both members of every user pair.

    Trees & Graphsgraphsset-intersectionsocial-network
  • Trees & GraphsEasyAuto-graded
    Shortcut by Adding Free Unit Edges

    Reason about degrees of freedom: since you may add arbitrary weight-1 edges, the optimal distance collapses to a constant.

    Trees & Graphsgraphsshortest-pathreasoningedge-cases
  • Trees & GraphsMediumAuto-graded
    Minimum Water Cells to Connect Two Land Masses

    Tests ability to combine flood-fill island identification with multi-source BFS to find the shortest water path bridging two disconnected land regions in a grid.

    Trees & Graphsbfsgridflood-fill
  • Trees & GraphsHardAuto-graded
    Filter Hierarchical Records by Ancestor Validity

    Tests memoized path traversal in a parent-pointer hierarchy with cycle detection and ancestral filtering rules.

    Trees & Graphsgraphsmemoizationcycle-detection
  • Trees & GraphsMediumAuto-graded
    Answer Reachability Queries on an Undirected Graph

    Build connected components from an edge list with Union-Find, then answer many connectivity queries quickly.

    Trees & Graphsunion-findgraphdisjoint-setconnectivity
  • Trees & GraphsMediumAuto-graded
    Best Meeting Point Across All Stations in a City Grid

    Tests multi-source BFS on a grid to find the open cell with the smallest total shortest-path distance to every station, respecting walls and blocked cells.

    Trees & Graphsbfsgridshortest-path
  • Trees & GraphsMediumAuto-graded
    Longest Path in an Undirected Tree

    Tests whether a candidate can find the longest edge-path in a tree using two linear-time traversals and reason about why the approach is correct.

    Trees & Graphsbfstreesgraph-traversal
  • Trees & GraphsMediumAuto-graded
    Fewest Cells Through a Diagonal-Move Grid

    Find the length of the shortest 8-directional clean-cell path across a square 0/1 grid using BFS.

    Trees & Graphsbfsgridshortest-path
  • Trees & GraphsMediumAuto-graded
    Virus Spread on a Grid

    Tests multi-source BFS on a 2D grid to find the minimum number of rounds for an infection to reach every susceptible cell, or detect if it cannot.

    Trees & Graphsbfsmatrixmulti-source
  • Trees & GraphsMediumAuto-graded
    Earliest-Arrival Reachability on Timed Transit Routes

    Tests whether a candidate can model time-respecting graph search over indexed transit routes to determine if a destination is reachable from a starting stop.

    Trees & Graphsgraph searchBFSgreedyshortest path
  • Trees & GraphsMediumAuto-graded
    Cheapest Type Transformation Path

    Tests shortest-path reasoning on a weighted directed graph, including source-caching strategy, zero-cost edges, unreachable nodes, and same-source queries.

    Trees & Graphsgraphsshortest-pathdijkstra
  • Trees & GraphsMediumAuto-graded
    Optimal Empty Cell with Minimum Path Distance Sum

    Tests multi-source BFS to find an empty cell minimizing total shortest-path distance to all targets on a grid with obstacles.

    Trees & Graphsbreadth-first-searchgraphsgrid-traversal
  • Trees & GraphsMediumAuto-graded
    Build Travel Route from Airline Tickets

    Tests directed graph traversal, Eulerian path construction, and lexicographical ordering with Hierholzer's algorithm.

    Trees & Graphsgraphsdfseulerian-pathbacktracking
  • Trees & GraphsMediumAuto-graded
    Flat Error Collection from a Recursive Schema Validator

    Tests ability to traverse a nested schema definition, flatten heterogeneous check results, and enforce a consistent empty-list contract across all node types.

    Trees & Graphsrecursionschema-validationflattening
  • Trees & GraphsMediumAuto-graded
    Alternating Direction Level Order Tree Traversal

    Tests BFS traversal with directional output reversal per level without corrupting the queue structure.

    Trees & Graphsbfsbinary-treelevel-orderqueue
  • Trees & GraphsHardAuto-graded
    Compute Division Chains from Given Ratios

    Tests graph modeling of multiplicative relationships and pathfinding to derive transitive ratios between variables.

    Trees & Graphsgraphbfsunion-find
  • Trees & GraphsMediumAuto-graded
    Match Documents Against Filter Expressions

    Build a recursive evaluator for filter expressions with logical operators and field comparisons, testing tree traversal and nested field lookup.

    Trees & Graphsrecursiontreesdictionaries