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 301–330 of 349 results

  • 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 & 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 & 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 & GraphsHardAuto-graded
    Minimum Cost Route with Limited Layovers

    Tests understanding of constrained shortest-path algorithms on directed weighted graphs with edge-count restrictions.

    Trees & Graphsgraphsshortest-pathbellman-fordconstraints
  • Trees & GraphsMediumAuto-graded
    Minimum Steps in Word Ladder

    Tests BFS on an implicit graph with efficient neighbor generation using wildcard pattern indexing.

    Trees & Graphsbfsgraphstringhashing
  • Trees & GraphsMediumAuto-graded
    Compute Minimum Distances to Multiple Destinations

    Tests understanding of single-source shortest path algorithms on weighted directed graphs with positive edge weights.

    Trees & Graphsshortest-pathdijkstragraph-traversalpriority-queue
  • Trees & GraphsMediumAuto-graded
    Island Detection and Letter Selection Counting

    Tests graph traversal for connected components in a binary grid and combinatorial counting with multiset constraints.

    Trees & Graphsgraph-traversalbfsconnected-componentscombinatorics
  • Trees & GraphsMediumAuto-graded
    Maximum Independent Set Weight on a Tree

    Tests tree DP by computing the maximum total weight of a node subset where no two chosen nodes share an edge (weighted tree independent set).

    Trees & Graphstreesdynamic programminggraph traversal
  • Trees & GraphsMediumAuto-graded
    Cell Formula Evaluator with Cycle Detection

    Build a mini spreadsheet engine that evaluates formulas, detects circular dependencies, and handles dynamic updates.

    Trees & Graphsgraphsdfsrecursionmemoization
  • Trees & GraphsMediumAuto-graded
    Count Separated Land Regions in a Binary Matrix

    Tests graph traversal skills by identifying connected components in a 2D grid using BFS or DFS.

    Trees & Graphsgraph-traversalbfsdfsconnected-components
  • Trees & GraphsMediumAuto-graded
    Largest Connected Land Region

    Measures understanding of graph traversal on a grid to compute connected-component sizes using four-directional adjacency.

    Trees & Graphsgraphsdfsconnected-componentsgrid-traversal
  • Trees & GraphsMediumAuto-graded
    Grid Infection Spread with Time Limit

    Tests BFS-based grid simulation with simultaneous state updates, barrier cells, and handling extremely large iteration counts efficiently.

    Trees & Graphsbfsgridsimulationqueue
  • Trees & GraphsEasyAuto-graded
    Tree Height Levels: Bottom-Up Node Grouping

    Compute each node's height in a rooted tree and group nodes by height, testing tree traversal and bottom-up computation.

    Trees & Graphstreesbfsheightbottom-up
  • Trees & GraphsHardAuto-graded
    Calculate Grid Infection Time

    Tests breadth-first search from multiple sources to model time-based propagation in a grid with obstacles and unreachable regions.

    Trees & Graphsbfsgridmulti-sourcegraph-traversal
  • Trees & GraphsMediumAuto-graded
    Identify the Nearest Shared Ancestor of Two Tree Nodes

    Tests tree reconstruction and ancestor tracking to locate the closest common parent of two given values in a binary tree.

    Trees & Graphsbinary-treetree-traversalancestor-search
  • Trees & GraphsMediumAuto-graded
    Minimax Solver for 3×3 Tic-Tac-Toe with Optimal Move Selection

    Implement a recursive game-tree solver that finds the outcome under optimal play and identifies a winning or drawing move for the current player.

    Trees & Graphsrecursionbacktrackinggame-theoryminimax
  • Trees & GraphsMediumAuto-graded
    Identify Tree Roots and Trace Ancestor Paths

    Tests graph traversal, parent-pointer navigation, and root identification in tree-like structures represented as parent references.

    Trees & Graphsgraphstreeshash-mapspath-finding
  • Trees & GraphsMediumAuto-graded
    Maximum Path Bonus in a Weighted Tree

    Tests tree DP (rerooting) by finding the node from which the maximum sum of weighted edges can be collected along any single root-to-leaf path in a tree.

    Trees & Graphstreesdynamic-programmingtree-dpdepth-first-search
  • Trees & GraphsMediumAuto-graded
    Subtree Sum Replacement in Level-Order Arrays

    Tests post-order traversal, heap indexing in complete binary trees, and efficient bottom-up aggregation without recursion.

    Trees & Graphsbinary-treespost-order-traversalcomplete-binary-treeaggregation
  • Trees & GraphsHardAuto-graded
    Earliest Moment a Social Network Becomes Fully Connected

    Tests offline dynamic graph connectivity using a segment-tree-over-time with a rollback-capable union-find to handle both edge insertions and deletions.

    Trees & Graphsunion-findsegment-treedynamic-connectivity
  • Trees & GraphsMediumAuto-graded
    Schedule Tasks With Resource Unlock Dependencies

    Tests ability to apply topological ordering to determine a valid execution sequence of tasks where each task may unlock resources required by others.

    Trees & Graphsgraphstopological sortDAGKahn's algorithm
  • Trees & GraphsMediumAuto-graded
    Aggregate User Permissions Through Account Ancestry

    Tests hierarchical graph traversal and efficient permission accumulation using ancestor path lookup and set operations.

    Trees & Graphsgraphstreesbfscaching
  • Trees & GraphsMediumAuto-graded
    Calculate Cumulative Task Weights in a Dependency Graph

    Tests graph traversal and dynamic programming on DAGs to compute propagated weight contributions through dependency chains.

    Trees & Graphsgraphsdagtopological-sortdynamic-programming
  • Trees & GraphsMediumAuto-graded
    Rank Build Targets by Dependency Order

    Tests whether a candidate can produce a valid topological ordering of a build-dependency DAG and apply a precise tie-break rule when multiple orderings exist.

    Trees & Graphsgraphstopological sortBFSKahn's algorithm