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 61–90 of 349 results
- Trees & GraphsEasyAuto-gradedLocate the Universally Followed Silent Guest
Find the one node in a directed relation that everyone points to and that points to nobody, using a linear elimination pass followed by verification.
Trees & Graphsgraphcelebrity-problemtwo-passelimination - Trees & GraphsMediumAuto-gradedTeardown Sequencing with Nested Ownership and Extra Prerequisites
Find the lexicographically smallest valid ordering of nodes under child-before-parent and extra precedence rules, or report impossibility when the rules contradict.
Trees & Graphstopological-sortheapcycle-detectiongraph - Trees & GraphsMediumAuto-gradedSemester Planner: Build a Valid Course Sequence
Produce a deterministic topological ordering of courses from prerequisite pairs, or an empty list when a circular requirement makes it impossible.
Trees & Graphstopological-sortgraphbfscycle-detection - Trees & GraphsMediumAuto-gradedEarliest Safe Starting Cell in a Jump Array
Find the smallest start index in a jump array whose walk never goes below index 0, handling cycles and right exits, ideally in linear time.
Trees & Graphsfunctional-graphcycle-detectionmemoizationarrays - Trees & GraphsMediumAuto-gradedRoute Between Two Nodes of an Implicit Recursive Tree
Find the unique path between two pre-order-indexed nodes in a huge recursively defined tree, using subtree sizes to navigate without building it.
Trees & Graphstreelcarecursionpre-order - Trees & GraphsMediumAuto-gradedStrongest Signal Route in a Lossy Link Network
Find the route between two nodes in an undirected graph that maximizes the product of per-link delivery probabilities, using a Dijkstra-style search with a max-priority queue.
Trees & Graphsgraphdijkstraheapshortest-path - Trees & GraphsMediumAuto-gradedBalanced BST Level-Order Output from a Sorted Sequence
Build a height-balanced BST from a sorted list using a fixed middle-element rule, then serialize it level by level with null placeholders.
Trees & Graphsbinary-search-treedivide-and-conquerrecursionlevel-order-traversal - Trees & GraphsMediumAuto-gradedLocked Gates Grid: Fewest Steps With Collected Keys
Find the fewest moves through a grid where lowercase cells give keys and uppercase cells are gates, using BFS over position plus the set of collected keys.
Trees & Graphsbfsgridstate-space-searchkeys-and-doors - Trees & GraphsMediumAuto-gradedReconstruct Hierarchical Execution Trees from Trace Records
Reassemble an unordered collection of trace span objects into a forest of child-linked execution trees sorted chronologically.
Trees & Graphstreeshash-tablesortinggraph - Trees & GraphsEasyAuto-gradedGroup Hierarchy Members by Depth Level
Construct an adjacency graph from reporting links and perform a level-order traversal to group node IDs by depth.
Trees & Graphstrees-graphsbfshash-map - Trees & GraphsMediumAuto-gradedBest Plot After Reclaiming a Single Water Tile
Find the largest connected land region achievable by turning at most one water cell into land, which tests component labeling and merging neighbors without double counting.
Trees & Graphsgridflood-fillconnected-componentsdfs - Trees & GraphsMediumAuto-gradedTwo Teams With Rival Pairs Kept Apart
Decide whether a set of people can be placed into two teams so that no rival pair shares a team, which tests graph 2-coloring across possibly disconnected components.
Trees & Graphsgraphbipartitebfscoloring - Trees & GraphsMediumAuto-gradedRender a Nested Folder Structure as Indented Lines
Traverse a nested dictionary tree in pre-order, tracking depth to build indented lines with a fixed marker, preserving the given child order.
Trees & Graphstree-traversaldfsstackstrings - Trees & GraphsMediumAuto-gradedCan Every Module in a Study Plan Be Finished?
Decide whether a set of ordering rules between numbered modules contains a circular dependency, by detecting a cycle in a directed graph.
Trees & Graphsgraphtopological-sortcycle-detectionbfs - Trees & GraphsMediumAuto-gradedMinimum Degrees of Separation in a Social Network
Determine the shortest path distance between two nodes in an unweighted, undirected graph using Breadth-First Search.
Trees & Graphsbfsgraphshortest-pathhash-map - Trees & GraphsMediumAuto-gradedMulti-Hop Currency Conversion Over a Rate Table
Compute a conversion factor between two currencies by chaining and inverting listed rates, returning -1.0 when no chain exists; tests graph traversal with multiplicative weights.
Trees & Graphsgraphbfshash-mapweighted-edges - Trees & GraphsMediumAuto-gradedSuggest Top Social Connection
Find the non-adjacent node in an undirected graph with the maximum count of shared neighbors relative to a target node.
Trees & Graphsgraphsbfshash-tablesocial-network - Trees & GraphsMediumAuto-gradedFind the Best-Paid Sub-Organization by Mean Pay
Aggregate subtree salary totals and headcounts bottom-up in a tree given as a flat list, then pick the best root using exact average comparison with size and id tie-breaks.
Trees & Graphstreedfspost-ordertie-breaking - Trees & GraphsHardAuto-gradedFewest Planks Across a Portal-Linked Board
Find the cheapest route on a grid with free, paid and blocked cells plus same-numbered teleport cells, which calls for 0-1 BFS and care with teleport expansion.
Trees & Graphs0-1 BFSshortest pathgridgraph modeling - Trees & GraphsMediumAuto-gradedCollect Every Value Stored Under a Key in Nested Data
Walk a nested structure of dicts and lists depth-first and gather every value stored under a given key, in traversal order, including matches inside already-matched values.
Trees & Graphsrecursiondfsjsontraversal - Trees & GraphsMediumAuto-gradedGenerate Preorder Depth Forest from Directed Node Pairs
Construct a hierarchical forest from directed child-parent relations and output a depth-annotated preorder traversal.
Trees & Graphstrees-graphsdepth-first-searchstackrecursion - Trees & GraphsMediumAuto-gradedBest Meeting Cell on a Grid with Walls
Find the open cell with the smallest total shortest-path distance to a set of target cells on a grid with obstacles, using BFS and reachability counting.
Trees & Graphsbfsgridshortest-pathgraph-traversal - Trees & GraphsMediumAuto-gradedTree Depth After Splicing Out Removed Nodes
Compute the depth of a rooted tree given as a parent array after splicing out marked nodes, so their children attach to the nearest surviving ancestor.
Trees & Graphstreebfsparent-arraydepth - Trees & GraphsMediumAuto-gradedBest Multi-Hop Exchange Rate Between Two Currencies
Find the largest product of directed exchange rates along any path between two currencies, using Bellman-Ford-style relaxation on a graph that may contain cycles and rates above 1.
Trees & Graphsgraphbellman-fordshortest-pathcurrency - Trees & GraphsEasyAuto-gradedGrid Zone Coloring Feasibility
Determine whether empty grid plots can be assigned one of k colors without adjacent conflicts.
Trees & Graphstrees-graphsarraysmath-bits - Trees & GraphsMediumAuto-gradedGrid Contagion Simulation
Simulate multi-source BFS propagation across a 2D grid up to a maximum number of steps.
Trees & Graphsbreadth-first-searchmatrixgraph-traversal - Trees & GraphsMediumAuto-gradedEarliest Finish Time for a Dependent Job Pipeline
Compute the shortest total time to finish all jobs with unlimited parallelism by finding the longest weighted path in a dependency graph, returning -1 if a cycle exists.
Trees & Graphstopological-sortdaglongest-pathdynamic-programming - Trees & GraphsMediumAuto-gradedSmallest Valid Order for Dependency Forest
Construct the lexicographically smallest topological ordering of nodes in a forest defined by an ancestor/parent mapping.
Trees & Graphstrees-graphsheaps-sortinggreedy-intervals - Trees & GraphsMediumAuto-gradedFewest Single-Letter Edits Through a Word List
Tests modeling word edits as an implicit graph and running BFS with wildcard buckets to find the minimum number of one-letter changes, with careful edge cases.
Trees & Graphsbfsgraphstringshashing - Trees & GraphsMediumAuto-gradedMaximum Pebble Removals on a Coordinate Board
Compute how many pebbles can be taken off a board when each removal needs another remaining pebble in the same row or column, using connected components.
Trees & Graphsunion-findconnected-componentsgraph-modelingdfs