KatInterview

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

Trees & Graphs Interview Problems

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

5971
Problems
2211
Auto-graded
15
Topics
272
Added today

Showing 271–300 of 349 results

  • Trees & GraphsMediumAuto-graded
    Verify BST Property on a Level-Order Encoded Tree

    Test whether a breadth-first list representation of a binary tree satisfies strict BST ordering without allowing duplicate values.

    Trees & Graphsbinary-treebstvalidation
  • Trees & GraphsHardAuto-graded
    Minimum Moves Across an Obstacle Grid

    Tests BFS-based shortest-path reasoning on an unweighted 2D grid with blocked cells and 4-directional movement.

    Trees & Graphsbfsgraph traversalgridshortest path
  • Trees & GraphsMediumAuto-graded
    Recursive Schema Validation

    Tests recursive validation of nested dictionaries against a schema with type and presence requirements.

    Trees & Graphsrecursionvalidationnested-structures
  • Trees & GraphsMediumAuto-graded
    Lexicographic Topological Sort of a Task Graph

    Tests directed graph construction, cycle detection via Kahn's algorithm, and deterministic tie-breaking with a min-heap to produce the lexicographically smallest valid ordering.

    Trees & Graphstopological-sortgraphsheaps
  • Trees & GraphsMediumAuto-graded
    Count Landlocked Islands

    Tests connected-component detection in grids with boundary constraints using BFS or DFS traversal.

    Trees & Graphsbfsdfsconnected-componentsgrid-traversal
  • Trees & GraphsMediumAuto-graded
    Build a Visual Directory Tree from Nested Dictionary

    Tests recursion, dictionary traversal, and string formatting to produce an indented tree structure with box-drawing connectors.

    Trees & Graphsrecursiontree-traversalstringsformatting
  • Trees & GraphsHardAuto-graded
    Prune All Leaves Matching a Value, Cascading Upward

    Tests whether a candidate can use post-order traversal to handle cascading leaf deletions in a binary tree encoded as a level-order list.

    Trees & Graphsbinary-treepost-order-traversalrecursiontree-serialization
  • Trees & GraphsMediumAuto-graded
    Subtree Erasure in an Array-Backed Binary Tree

    Tests implicit heap-tree traversal, subtree identification via index arithmetic, and stable compaction without mutating the input array.

    Trees & Graphstrees-graphsarraysbfs-dfs
  • Trees & GraphsMediumAuto-graded
    Minimum Hops Between Nodes in a Matrix-Represented Graph

    Tests ability to implement BFS on an undirected unweighted graph stored as an adjacency matrix to find the fewest edges between two nodes.

    Trees & Graphsgraphsbfsadjacency-matrix
  • Trees & GraphsMediumAuto-graded
    Minimum Collections to Link Two Items

    Tests bipartite graph traversal and BFS to find shortest paths alternating between items and their containing collections.

    Trees & Graphsgraph-theorybfsbipartite-graph
  • Trees & GraphsMediumAuto-graded
    Detect Cycles in a Package Dependency Graph

    Tests ability to detect cycles in a directed graph using DFS-based cycle detection, modelling package dependencies where a cycle makes installation impossible.

    Trees & Graphsgraphscycle detectiondepth-first searchtopological order
  • Trees & GraphsHardAuto-graded
    Reduce Worst-Case Coverage Gap with One New Relay Node

    Tests binary search on answer combined with multi-source BFS and 2D prefix sums to optimally place one relay node and minimize the maximum Chebyshev coverage distance.

    Trees & Graphsbinary-searchbfsmatrixprefix-sums
  • Trees & GraphsMediumAuto-graded
    Axis-Aligned Bounding Boxes of Grid Regions

    Tests BFS/DFS connected-components traversal on a 2D grid to locate distinct filled regions and compute the tightest enclosing rectangle for each.

    Trees & Graphsbfsdfsconnected-componentsgrid
  • Trees & GraphsMediumAuto-graded
    Shortest Path Through a Grid With Keys and One-Way Portals

    Tests BFS/Dijkstra on an augmented state space where position must be combined with a key-collection bitmask, and directional arrow tiles enforce constrained traversal.

    Trees & Graphsbfsdijkstrabitmaskgrid
  • Trees & GraphsMediumAuto-graded
    Lexicographically Smallest Schedule or Detect a Deadlock

    Tests Kahn's algorithm with a min-heap to produce the lexicographically smallest valid processing order across nodes in a directed dependency graph, or detect a cycle.

    Trees & Graphstopological-sortgraphsheap
  • Trees & GraphsMediumAuto-graded
    Spell Words Along Connected Paths in a Letter Grid

    Tests backtracking DFS with trie-based pruning to find all words from a large list that can be traced through edge-adjacent, non-repeating cells in a 2-D letter grid.

    Trees & Graphsbacktrackingtriedfs
  • Trees & GraphsMediumAuto-graded
    Find Valid Completion Sequence for Dependent Tasks

    Tests understanding of topological sorting, dependency graph modeling, and cycle detection in directed acyclic graphs.

    Trees & Graphstopological-sortgraphsbfscycle-detection
  • Trees & GraphsEasyAuto-graded
    Paint Bucket: Recolor a 4-Connected Region in a Grid

    Tests BFS/DFS grid traversal by spreading a new color through all 4-directionally connected cells sharing the starting cell's original color.

    Trees & Graphsbfsgridgraph-traversal
  • Trees & GraphsMediumAuto-graded
    Cluster Interchangeable Words by Surrounding Context

    Tests context hashing, union-find for transitive closure, and precise output formatting to group words that are mutually substitutable in identical four-word windows.

    Trees & Graphsunion-findhashingstrings
  • Trees & GraphsMediumAuto-graded
    Shortest Path Through a Network With Hazardous Nodes

    Tests BFS on filtered graphs and Dijkstra with lexicographic two-criteria cost to navigate networks while minimizing hazardous-node visits then total hops.

    Trees & Graphsbfsdijkstrashortest-path
  • Trees & GraphsMediumAuto-graded
    Assemble a Binary Tree from Two Traversals, Output by Level

    Tests whether a candidate can reconstruct a unique binary tree from its preorder and inorder sequences and serialize the result breadth-first with null markers.

    Trees & Graphsbinary-treetraversalBFSiterative
  • Trees & GraphsMediumAuto-graded
    Build Installation Order from Package Dependencies

    Tests graph traversal with cycle detection to compute a valid installation sequence for packages with dependencies.

    Trees & Graphsgraph-traversaltopological-sortcycle-detectiondfs
  • Trees & GraphsHardAuto-graded
    Virus Spread Simulation with Recovery and Infection Thresholds

    Models discrete-time epidemic propagation on a grid where cells require multiple infected neighbors to catch the virus and recover after a fixed duration.

    Trees & Graphssimulationbfsgraph-traversal
  • Trees & GraphsMediumAuto-graded
    Count Connected Land Regions in a Binary Grid

    Tests iterative 2D graph traversal to count connected components of land cells without modifying the input or risking recursion stack overflow.

    Trees & Graphsgraph traversalBFS/DFSconnected componentsgrid
  • Trees & GraphsHardAuto-graded
    Detect File Changes Using Content-Based Tree Hashing

    Tests hierarchical hashing, tree traversal, and efficient change detection across nested directory structures

    Trees & Graphshashingtree-traversaldiff-algorithms
  • Trees & GraphsMediumAuto-graded
    Largest Land Mass After One Water-to-Land Conversion

    Tests grid connected-component labeling and the ability to optimally merge adjacent island regions by flipping a single water cell to land.

    Trees & Graphsgraphbfs-dfsconnected-componentsgrid
  • Trees & GraphsMediumAuto-graded
    Smallest Valid Sequence with Dependencies

    Tests topological sorting with lexicographic tie-breaking and cycle detection in a directed graph.

    Trees & Graphstopological-sortgraphheapcycle-detection
  • Trees & GraphsMediumAuto-graded
    Resolve Variable Dependencies with Arithmetic

    Tests dependency graph traversal, cycle detection, and recursive evaluation of variables defined by arithmetic expressions.

    Trees & Graphsrecursiongraph-traversalcycle-detectionparsing
  • Trees & GraphsMediumAuto-graded
    Network Unification Timestamp

    Tests Union-Find data structure application to track dynamic graph connectivity and determine when all nodes merge into one component.

    Trees & Graphsunion-finddisjoint-setgraph-connectivity
  • Trees & GraphsHardAuto-graded
    Minimum Steps to Collect All Keys in a Grid Maze

    Tests BFS shortest path on a grid where state must encode both position and the set of collected keys, requiring multi-dimensional state space exploration.

    Trees & Graphsgraphsbfsgridbitmask