KatInterview

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

Trees & Graphs Interview Problems

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

5976
Problems
2213
Auto-graded
15
Topics
271
Added today

Showing 211–240 of 349 results

  • Trees & GraphsMediumAuto-graded
    Grid Obstacle Distances and Palindrome Ancestor Paths

    Tests two skills at once: directional obstacle scanning on a 2D grid, and bitmask-based palindrome counting over rooted-tree ancestor segments.

    Trees & Graphsgridbit-manipulationdfs
  • Trees & GraphsMediumAuto-graded
    Balance Root-to-Leaf Path Sums in Binary Tree

    Tests bottom-up tree traversal with greedy balancing, recognizing that shared ancestors minimize total increments across multiple paths.

    Trees & Graphsbinary-treegreedypost-order-traversaltree-dp
  • Trees & GraphsMediumAuto-graded
    Minimum Steps Through an Obstacle Map

    Tests ability to model a 2D grid as an unweighted graph and apply BFS to find the fewest moves between two corners while avoiding walls.

    Trees & Graphsbfsgraphsgrid
  • Trees & GraphsMediumAuto-graded
    Count Land Cells in a Connected Region

    Tests iterative graph traversal (DFS/BFS) on a binary grid, including bounds handling, visited-marking strategy, and complexity analysis.

    Trees & Graphsgraph traversalDFSBFSmatrix
  • Trees & GraphsMediumAuto-graded
    Bottleneck Path Under an Edge-Weight Cap

    Tests whether a candidate can find the minimax-cost path in a filtered graph, recognising that one edge attribute gates inclusion while another drives the optimisation.

    Trees & Graphsgraphdijkstraminimaxshortest-path
  • Trees & GraphsMediumAuto-graded
    Letter Access Sets Through a Dependency Graph

    Tests topological processing of a DAG where each node computes an active letter set from its parents' resolved sets plus its own additions and removals.

    Trees & Graphstopological-sortbit-manipulationgraph
  • Trees & GraphsMediumAuto-graded
    Flood Fill with Step Budget on an 8-Connected Grid

    Tests BFS-based grid traversal by counting distinct empty cells reachable from a starting position within a fixed number of 8-directional moves.

    Trees & Graphsbfsgridgraph-traversal
  • Trees & GraphsEasyAuto-graded
    Tree Traversal with Depth Tracking

    Tests your ability to perform pre-order depth-first traversal on a tree structure and track hierarchical depth for each node.

    Trees & Graphstree-traversaldfsdepth-tracking
  • Trees & GraphsMediumAuto-graded
    Shared Root of Two Nodes in a Binary Search Tree

    Tests whether a candidate can exploit BST ordering to locate the deepest node that is an ancestor of both targets without searching the entire tree.

    Trees & Graphsbinary-search-treelowest-common-ancestortree-traversal
  • Trees & GraphsMediumAuto-graded
    Left and Right View of a Binary Tree Using BFS and DFS

    Tests understanding of binary tree traversal by computing boundary nodes at each depth using both breadth-first and depth-first strategies.

    Trees & Graphsbinary-treebfsdfstree-traversal
  • Trees & GraphsMediumAuto-graded
    Multi-Part Algorithm Challenge: Grids, Medians, and Traversals

    Tests implementation of connected-component search in grids, efficient median computation across sorted sequences, and breadth-first and depth-first graph traversals.

    Trees & Graphsgraphsarraysbinary-searchbfs
  • Trees & GraphsMediumAuto-graded
    Assemble Tree from Edge Specifications

    Tests building a tree structure from unordered edge list by tracking node relationships and identifying the root.

    Trees & Graphstreeshash-tablegraph-construction
  • Trees & GraphsMediumAuto-graded
    Equal Binary Digits and Ascending Tree Chain

    Tests prefix-sum balancing for binary arrays and depth-first search for strictly increasing root-to-leaf paths in binary trees.

    Trees & Graphstreesarraysprefix-sumdfs
  • Trees & GraphsHardAuto-graded
    Detect a Profitable Currency Trade Loop

    Tests whether you can model exchange rates as a weighted directed graph and apply Bellman-Ford to detect a cycle whose rate product exceeds 1.

    Trees & Graphsgraphsbellman-fordlogarithms
  • Trees & GraphsMediumAuto-graded
    Reachable Stocked Nodes Within a Hop Limit

    Tests BFS on an undirected graph to filter nodes by shortest-path distance and a secondary inventory condition, including edge-case handling for missing keys and duplicates.

    Trees & Graphsbfsgraphsshortest-path
  • Trees & GraphsMediumAuto-graded
    Resolve Boolean Signal Chains with Negation and Cycle Detection

    Tests iterative functional-graph traversal: propagating True/False through chains of references and NOT, while correctly marking cycles, dangling references, and their dependents as unresolvable.

    Trees & Graphsgraph traversalcycle detectionhash map
  • Trees & GraphsMediumAuto-graded
    Extract String Leaf Paths from Nested JSON Structure

    Traverse nested dictionaries and lists to collect dot-and-bracket paths to all string values, returned in sorted order.

    Trees & Graphstree-traversaliterationstackpath-building
  • Trees & GraphsMediumAuto-graded
    Group Serialized Tree Values by Depth

    Parse a LeetCode-style level-order array and return values grouped into nested lists by depth, preserving left-to-right order.

    Trees & Graphstreesbfsarrays
  • Trees & GraphsMediumAuto-graded
    Shared Manager in Organizational Hierarchy

    Tests tree traversal, ancestor queries, and handling multiple input formats with a custom precedence rule.

    Trees & Graphstreeslowest-common-ancestorgraph-traversal
  • Trees & GraphsMediumAuto-graded
    Fill Rooms With Distance to Nearest Exit

    Tests multi-source BFS on a grid to propagate shortest walking distances from all exits simultaneously to every reachable empty room.

    Trees & Graphsbfsgraphsgrid
  • Trees & GraphsMediumAuto-graded
    Root-to-Leaf Path Metrics on a Weighted Tree

    Tests whether a candidate can traverse an unordered weighted tree in linear time to extract the root, the heaviest root-to-leaf path weight, and the maximum depth.

    Trees & Graphstrees-graphshash-mapiterative-dfs
  • Trees & GraphsMediumAuto-graded
    Place One Beacon to Minimize Peak Shadow Distance

    Tests binary search on a monotone feasibility predicate combined with multi-source BFS and Chebyshev distance geometry on a 2-D grid.

    Trees & Graphsbfsbinary-searchgrid
  • Trees & GraphsMediumAuto-graded
    Recursive Region Tree and Safe Graph Nodes

    Tests recursive spatial subdivision (quadtree construction) and graph cycle detection (identifying nodes that always terminate).

    Trees & Graphsrecursiongraphsdivide-and-conquertopological-sort
  • Trees & GraphsMediumAuto-graded
    Convert Nested Dictionary to Dot-Separated Keys

    Tests ability to traverse nested data structures and transform hierarchical key-value pairs into a flat representation using path notation.

    Trees & Graphsrecursioniterationdictionarytree-traversal
  • Trees & GraphsMediumAuto-graded
    Column-Ordered Tree Values From a Level-Order Array

    Bucket level-order tree nodes by column, then sort each column by depth and value to produce the grouped output.

    Trees & Graphsbinary-treebreadth-first-searchsortinghash-map
  • Trees & GraphsMediumAuto-graded
    Largest Label Spread Across Graph Clusters

    Tests ability to find connected components in an undirected graph and compute the maximum difference between the highest and lowest node labels in any single component.

    Trees & Graphsunion-findgraphsconnected-components
  • Trees & GraphsHardAuto-graded
    Shortest Supplier Chain Between Two Vendors

    Tests BFS-based shortest-path traversal on an undirected graph, including path reconstruction and degree-of-separation counting with correct edge-case handling.

    Trees & GraphsgraphsBFSshortest-path
  • Trees & GraphsMediumAuto-graded
    Connected Land Regions on a Grid (8-Direction)

    Tests graph traversal skills by counting connected components in a character grid where land cells are neighbours in all eight directions including diagonals.

    Trees & Graphsgraph traversalBFS/DFSflood fillconnected components
  • Trees & GraphsMediumAuto-graded
    Group Accounts by Shared Identity Fields

    Tests the ability to model transitive relationships between records using Union-Find (DSU) to identify connected components linked by shared attribute values.

    Trees & Graphsunion-findconnected-componentshashing
  • Trees & GraphsMediumAuto-graded
    Find the Hub Node in a Star-Shaped Network

    Tests recognition of star-graph topology and the insight that the central node is uniquely identified by its degree.

    Trees & Graphsgraphsdegreestar-graph