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 361–390 of 434 results

  • 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 & GraphsMediumModel answer
    Multi-Problem Algorithm Sprint: Trees, Grids, and Heaps

    Implement six independent algorithm problems covering BST operations, tree traversals, optimization, and graph exploration with correctness and complexity analysis.

    Trees & Graphsbinary-treesbinary-search-treesgraph-traversaloptimization
  • 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 & GraphsMediumModel answer
    Maze Exploration with Limited Sensor API

    Explore an unmapped grid using a restricted movement API to find a target location, tracking state through relative coordinates.

    Trees & Graphsgraph-traversaldfsstate-trackingbacktracking
  • 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 & GraphsMediumModel answer
    Employee Hierarchy: Counting Trees, Level Traversal, and Ancestor Search

    Build a management structure from employee records, then count independent hierarchies, display staff by organizational depth, and locate shared supervisors.

    Trees & Graphstree-constructionlevel-order-traversallowest-common-ancestorgraph-fundamentals
  • 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 & GraphsMediumModel answer
    Resolve Variable Assignments with Dependencies

    Parse assignment statements and compute a variable's value by recursively resolving dependencies, detecting cycles and undefined references.

    Trees & Graphsrecursiongraphsparsingdfs
  • 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 & GraphsMediumModel answer
    Grid Containment: Minimum Removals to Stop Spread

    Find the fewest cells to remove from a grid to prevent infection from spreading to healthy neighbors.

    Trees & Graphsbipartite-matchinggraph-theorygridvertex-cover
  • Trees & GraphsMediumModel answer
    Compute Direct and Total Network Reach for Each User

    Given a list of sponsor–member pairs, return the direct and full downstream unique reach count for every user, handling duplicates, converging paths, and cycles.

    Trees & GraphsgraphsBFSreachabilitycycles
  • 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
  • Trees & GraphsMediumModel answer
    Chain Fragment Payloads by Matching Tags

    Order tagged fragments so each fragment's ending tag matches the next fragment's starting tag, then concatenate their payloads into a single output string.

    Trees & Graphsgraphsstring-manipulationgraph-traversal
  • Trees & GraphsMediumAuto-graded
    Count Separate Land Regions in a Grid

    Tests flood-fill traversal to identify connected components in a 2D grid with four-directional adjacency.

    Trees & Graphsgraphsbfsdfsconnected-components
  • Trees & GraphsMediumAuto-graded
    Collect Binary Tree Node Values in Left-Root-Right Order

    Tests binary tree traversal using an explicit stack to visit nodes in left-root-right sequence from a level-order serialized input.

    Trees & Graphsbinary-treetraversalstackdeserialization
  • Trees & GraphsMediumAuto-graded
    Filter Users by Active Connection Threshold

    Tests graph maintenance with dynamic edge insertion and deletion, proper handling of duplicates and missing edges, and final degree counting.

    Trees & Graphsgraphshash-tablesimulation
  • Trees & GraphsMediumAuto-graded
    Minimum-Length Root-to-Leaf Path with Target Sum

    Tests tree traversal with state tracking to identify the shortest valid path satisfying a sum condition.

    Trees & Graphsbinary-treedfspath-finding
  • Trees & GraphsMediumAuto-graded
    Signal Propagation Time to All Destinations

    Tests understanding of multi-source BFS to compute the longest shortest path from any source to all required destinations on a grid with obstacles.

    Trees & Graphsbreadth-first-searchgridmulti-source-bfsshortest-path
  • Trees & GraphsMediumModel answer
    Weighted Grid Navigation: Minimum Cost Path Around Walls

    Find the cheapest path through a cost-weighted grid containing impassable walls, returning the total cost and route, or -1 if no path exists.

    Trees & Graphsdijkstrapriority-queueshortest-pathgrid
  • Trees & GraphsMediumAuto-graded
    Lowest Shared Ancestor in Organization Hierarchy

    Finding the deepest node that lies on the upward path to the root for all given employees in a tree structure.

    Trees & Graphstreelowest-common-ancestordepth-first-searchbreadth-first-search
  • Trees & GraphsMediumModel answer
    Timestamp When All Users Form a Single Connected Group

    Given users and a chronological log of pairwise interactions, determine when everyone first becomes transitively connected through interaction chains.

    Trees & Graphsunion-findgraph-connectivitytemporal-graphdisjoint-set
  • Trees & GraphsHardAuto-graded
    Feature Deployment with Integrity Checks and Dependency Ordering

    Verify configuration integrity using polynomial hashing, detect dependency cycles with DFS, and produce a lexicographically-ordered topological deployment sequence.

    Trees & Graphsgraph-traversaltopological-sorthashingcycle-detection
  • Trees & GraphsHardAuto-graded
    Build Frequency-Based Binary Codec

    Tests ability to construct a deterministic frequency tree with tie-breaking, generate prefix-free binary codes, and encode/decode strings.

    Trees & Graphstreesheapsgreedybit-manipulation
  • Trees & GraphsMediumAuto-graded
    Compute Subtree Sums from Parent Array

    Tests bottom-up aggregation in trees represented as parent arrays, requiring iterative traversal to avoid recursion limits on deep trees.

    Trees & Graphstreespost-orderaggregationiterative
  • Trees & GraphsMediumModel answer
    Recursive Disk Transfer Between Three Pegs

    Move n disks from one peg to another using a spare peg, one at a time, never placing a larger disk on a smaller one.

    Trees & Graphsrecursionalgorithm-designcomplexity-analysis