practice a little every day — you've got this ♡
Trees & Graphs Interview Problems
Practice 5979 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.
- 5979
- Problems
- 2215
- Auto-graded
- 15
- Topics
- 273
- Added today
Showing 181–210 of 349 results
- Trees & GraphsMediumAuto-gradedNet Access Letters Across a Dependency Hierarchy
Compute each node's final letter set in a DAG where grants flow to all descendants but revocations apply only to the node that declares them.
Trees & Graphsgraphdagtopological-sortbitmask - Trees & GraphsMediumAuto-gradedBatch Ratio Lookup Over Linked Quantities
Answer many ratio queries between named quantities from pairwise ratio facts, using a weighted union-find or component precomputation instead of a search per query.
Trees & Graphsunion-findgraphweighted-union-findbatch-queries - Trees & GraphsMediumAuto-gradedLargest Chain Reaction From a Single Detonation
Model one-way blast reach as a directed graph and find the largest set reachable from any single starting node, using exact integer distance checks.
Trees & Graphsgraphdfsreachabilitygeometry - Trees & GraphsMediumAuto-gradedFind the Exit of a Keyed Forest Graph
Run a breadth-first search over (location, keys held) states in a forest with locked doors to find the first exit reached, or None.
Trees & Graphsbfsgraphstate-space-searchparsing - Trees & GraphsMediumAuto-gradedColumn Grid from a Tree: Reach a Value by Walking Non-Zero Cells
Project a heap-indexed binary tree onto a depth-by-column grid, then use BFS over non-zero cells to decide whether a cell holding the target is reachable from a given start.
Trees & Graphsbinary-treebfsgridvertical-order - Trees & GraphsMediumAuto-gradedEager Formula Sheet with Cycle-Safe Updates
Simulate a mini spreadsheet where formulas are evaluated at write time, dependents update eagerly, and any write that would create a dependency cycle is rejected without changing state.
Trees & Graphsdependency graphtopological sortcycle detectionsimulation - Trees & GraphsMediumAuto-gradedDuplicate a Nested Structure With Cycles and Shared Parts
Build an independent deep copy of a nested container structure, preserving shared references and cycles, using a memo table and an explicit stack.
Trees & Graphsdeep-copygraph-traversalmemoizationiterative-dfs - Trees & GraphsMediumAuto-gradedUncover Cells on a Minefield Grid with Flood Expansion
Apply a Minesweeper-style tap to a grid, expanding through zero-mine regions with breadth-first search and labeling cells with adjacent mine counts.
Trees & Graphsbfsgridmatrixsimulation - Trees & GraphsMediumAuto-gradedGrid Distance to the Closest Marked Cell
Compute, for every cell of a grid, the fewest orthogonal steps to the closest marked cell, using a single multi-source breadth-first search; -1 everywhere when no cell is marked.
Trees & Graphsbfsmulti-source-bfsgridshortest-path - Trees & GraphsMediumAuto-gradedChained Exchange Rates: Resolve Conversion Queries
Build a bidirectional weighted graph from exchange rates and answer conversion queries with a deterministic BFS that multiplies rates along the first-found path, or -1.0 if none exists.
Trees & Graphsgraphbfsweighted-graphhash-map - Trees & GraphsMediumAuto-gradedIs the Target's Cell Forced by Every Valid Seating?
Backtracking over placements of named items on a grid under pairwise relative-position clues, deciding whether the target ends up in one cell across all valid layouts.
Trees & Graphsbacktrackingconstraint-satisfactiongridsearch - Trees & GraphsHardAuto-gradedSemester Planner Plus Burst-Limited Request Filter
Combine topological ordering to find the minimum number of semesters (or detect a cycle) with a deque-based simulation of a two-rule request throttle that reports dropped timestamps.
Trees & Graphstopological-sortgraphcycle-detectionsliding-window - Trees & GraphsMediumAuto-gradedLive Archipelago Counter with Incremental Land Reclamation
Count 4-connected land regions in a grid, then report the updated region count after each cell is converted from water to land, using incremental connectivity.
Trees & Graphsunion-findgridconnected-componentsincremental-updates - Trees & GraphsMediumAuto-gradedCheapest Letter Rewrites with Directed Price Rules
Compute the minimum cost to rewrite one string into another with directed priced letter swaps, using shortest paths over 26 letters and handling impossible positions and large totals.
Trees & Graphsgraphfloyd-warshallshortest-pathstrings - Trees & GraphsMediumAuto-gradedFewest-Hop Route Through Flaky Page Fetches
Run BFS on a link graph to find the lexicographically smallest fewest-hop route, where some pages fail a set number of times before their links load.
Trees & Graphsbfsgraphshortest-pathretries - Trees & GraphsMediumAuto-gradedRainbow Walks of Length Three in a Typed Graph
Count ordered 4-vertex walks along edges in an undirected graph whose vertices carry one of four labels, where each walk uses every label exactly once.
Trees & Graphsgraphcountingcombinatoricsadjacency-list - Trees & GraphsMediumAuto-gradedEarliest Finish Time for a Dependent Task Pipeline
Find the minimum time to complete all tasks with durations and prerequisites under unlimited parallelism, or detect a circular dependency, using longest path in a DAG with topological ordering.
Trees & Graphstopological-sortgraphdaglongest-path - Trees & GraphsMediumAuto-gradedFlip Pipes to Flow Outward From a Source Station
Count the directed edges of a tree that point toward a chosen root, which is the minimum number of flips needed to orient every edge away from it.
Trees & Graphstreegraph-traversaldfsbfs - Trees & GraphsMediumAuto-gradedGrid Contagion with Neighbor-Count Thresholds
Compute when each grid cell becomes infected under a synchronous neighbor-count rule, using a multi-source BFS that updates counts incrementally instead of rescanning each round.
Trees & Graphsbfsgridsimulationmulti-source-bfs - Trees & GraphsMediumAuto-gradedLeftmost and Rightmost Nodes per Depth from a Serialized Tree
Given a level-order serialized binary tree, return the first and last node value at each depth, testing BFS over an array-encoded tree and careful handling of null slots.
Trees & Graphsbinary-treebfslevel-orderserialization - Trees & GraphsMediumAuto-gradedLongest Path Between Any Two Nodes in an Indexed Binary Tree
Find the longest path, counted in edges, between any two nodes of a binary tree stored as a child-index list, testing tree height computation and avoiding deep recursion.
Trees & Graphsbinary-treedfsbfstree-height - Trees & GraphsMediumAuto-gradedRebuild a Search Tree from Its Preorder Listing
Rebuild a binary search tree from its preorder listing of distinct integers in linear time, then report it in level order with null placeholders. Tests stack-based construction and BFS serialization.
Trees & Graphsbinary-search-treestackpreorderbfs - Trees & GraphsMediumAuto-gradedCombine Config Trees and Parse a Canonical Encoding
Merge two keyed n-ary trees by summing values, encode them canonically, and strictly parse an encoded string with validation.
Trees & Graphstreerecursionparsingserialization - Trees & GraphsMediumAuto-gradedSmallest Job Schedule Under Dependency Rules
Produce the lexicographically smallest topological ordering of a dependency graph, or an empty list if the dependencies contain a cycle.
Trees & Graphstopological-sortgraphheapcycle-detection - Trees & GraphsMediumAuto-gradedBalance Path Totals in a Rooted Tree with Minimum Bumps
Compute the fewest +1 increments that make every root-to-leaf path total equal in a large rooted tree given as a parent array, which needs a bottom-up greedy and an iterative traversal.
Trees & Graphstreegreedybfstree-dp - Trees & GraphsMediumAuto-gradedCourse Plan Builder with Already-Passed Classes
Build a valid course order from prerequisite pairs while skipping passed courses, using a topological sort with a fixed tie-break order and cycle detection.
Trees & Graphstopological-sortgraphbfscycle-detection - Trees & GraphsMediumAuto-gradedRetrieve Kth Smallest Element from Array-Encoded BST
Tests in-order traversal of a binary search tree encoded in parallel arrays, with early termination and iterative stack management.
Trees & Graphsbinary-search-treein-order-traversaliterativestack - Trees & GraphsMediumAuto-gradedCount Reachable Cell Clusters in a Grid
Tests grid-based connected-components detection using flood-fill or DFS, covering neighbor connectivity, visited-state tracking, and iterative traversal.
Trees & Graphsgraphsgriddfsconnected-components - Trees & GraphsMediumAuto-gradedFold and Prune an Arithmetic Expression Tree
Tests recursive AST traversal by simplifying an arithmetic expression tree through constant folding and algebraic identity rules, including cascading rewrites.
Trees & Graphstreesrecursionast - Trees & GraphsHardAuto-gradedDiff Two Versions of a Configuration Tree
Tests recursive-free N-ary tree traversal and set-based diffing to count nodes added, removed, or modified between two tree snapshots.
Trees & Graphstreeshashingtraversal