KatInterview

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

Trees & Graphs Interview Problems

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

5978
Problems
2214
Auto-graded
15
Topics
272
Added today

Showing 271–300 of 434 results

  • Trees & GraphsMediumModel answer
    Threaded Comment Feed: Filtering, Nesting, and Persistent Sort

    Transform a flat array of comments into a sorted, nested, filterable tree while persisting the user's sort preference across sessions.

    Trees & Graphstree-constructiondfslocalStoragefrontend-data
  • 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 & GraphsMediumModel answer
    Content-Based Duplicate File Detector

    Recursively scan a directory tree, group files by size then content hash, and return every set of two or more paths that hold identical bytes.

    Trees & Graphshashingfile-systemtraversaldeduplication
  • Trees & GraphsMediumModel answer
    Find the Longest Path in an Undirected Tree

    Given a tree as an adjacency list, return the sequence of nodes forming its diameter — the longest simple path between any two nodes.

    Trees & GraphsBFSDFStree diameterpath reconstruction
  • 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 & GraphsHardModel answer
    Check Whether a Node Sequence Is a Valid BFS on a Tree

    Given an undirected tree and multiple permutations of its nodes, determine for each permutation whether it could be the dequeue order of some BFS starting at its first element.

    Trees & GraphsBFStreessimulationhashing
  • Trees & GraphsMediumModel answer
    Height-Balanced Nodes in Heap-Array Trees

    Traverse a binary tree stored in heap-index layout to find every node whose subtree is height-balanced, returning each with its tree level.

    Trees & Graphsbinary-treepost-orderheap-layoutbottom-up
  • 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 & GraphsMediumModel answer
    Nearest Depot and Peak-Load Routing on a Grid

    Given a grid with depot cells, find shortest paths from query locations to any depot, then extend to pick the depot maximizing a distance-penalized load score.

    Trees & GraphsBFSDijkstramulti-sourcegrid
  • 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 & GraphsMediumModel answer
    Propagating Allow/Deny Permissions Through an Inheritance DAG

    Given a DAG where each node carries allow and deny lists, compute every node's effective permissions by inheriting and merging rules along edges in topological order.

    Trees & Graphsgraphstopological-sortpermissionsDAG
  • Trees & GraphsMediumModel answer
    Rebuild a Binary Tree from Pre- and In-Order Sequences

    Given preorder and inorder traversal arrays of a binary tree with unique values, reconstruct the tree in O(n) time and O(n) space.

    Trees & Graphsbinary-treerecursionhash-maptraversal
  • Trees & GraphsMediumModel answer
    Closest Shared Ancestor for a Group of Org-Chart Nodes

    Build a validated org-chart tree from manager–report pairs and find the deepest node that is an ancestor of every node in a given set.

    Trees & Graphslowest-common-ancestorbinary-liftingtree-traversalinput-validation
  • Trees & GraphsMediumModel answer
    Chain All Words Into One String via Shared Letters

    Given a list of words, merge them into one string by joining where each word's last letter matches the next word's first letter, dropping the duplicate.

    Trees & Graphseulerian-pathgraphstringshierholzer
  • 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