practice a little every day — you've got this ♡
Trees & Graphs Interview Problems
Practice 5980 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.
- 5980
- Problems
- 2215
- Auto-graded
- 15
- Topics
- 272
- Added today
Showing 241–270 of 434 results
- 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 & GraphsMediumModel answerThread-Pooled Link Crawler with Depth Limit and Dedup
Implement a thread-safe crawler that explores links from a seed page to a given depth, never fetches a URL twice, and caps the number of simultaneous fetches.
Trees & Graphsconcurrencybfsthread-poolgraph-traversal - 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 & GraphsMediumModel answerRound-Trip Text Encoding for Ordered Trees with Any Number of Children
Define a text format for ordered trees with arbitrary branching, then write an encoder and decoder that rebuild the exact same values, structure and child order in linear time.
Trees & Graphstreeserializationn-ary-treeiterative-dfs - 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 & GraphsHardModel answerRewrite a Relational Plan: Sink Filters and Trim Columns
Transform a tree of Scan, Filter, Project and Join operators by moving filters toward the leaves and removing unused columns, while keeping query results unchanged.
Trees & Graphstree-rewritingquery-optimizationpredicate-pushdownprojection-pruning - 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 & GraphsMediumModel answerCount All Valid 4×4 Three-in-a-Row Game Sequences
Use recursion and backtracking to enumerate every ordered move sequence on a 4×4 board where three consecutive marks (not four) wins.
Trees & Graphsbacktrackingrecursiongame-treecombinatorics - 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 & GraphsMediumModel answerCurrency Conversion Rates via Graph Traversal
Build a weighted graph from currency pairs and answer conversion queries, then extend to directional rates and arbitrage detection.
Trees & Graphsgraph-traversalshortest-pathbellman-fordfloating-point - 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 - Trees & GraphsMediumAuto-gradedGrid 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 & GraphsMediumModel answerMinimum Spread Time for Contamination in a Grid
Find how many steps a contamination spreads from multiple sources through a grid, or determine if some cells remain permanently unaffected.
Trees & GraphsBFSmulti-source BFSgrid traversalshortest path - Trees & GraphsMediumAuto-gradedBalance 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 & GraphsMediumModel answerTrace a Target String Through a Character Grid
Decide whether a word can be spelled by a non-repeating, four-directional path of adjacent cells in a character matrix, with pruning and complexity analysis.
Trees & Graphsbacktrackingdepth-first-searchgridpruning - Trees & GraphsMediumAuto-gradedMinimum 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-gradedCount 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-gradedBottleneck 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 & GraphsMediumModel answerCollapsible Nested Menu with ARIA Support
Design and code a React component that displays hierarchical data with interactive expand/collapse behavior and full keyboard accessibility.
Trees & Graphsreactrecursionaccessibilitystate-management - Trees & GraphsMediumAuto-gradedLetter 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-gradedFlood 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-gradedTree 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