practice a little every day — you've got this ♡
Trees & Graphs Interview Problems
Practice 5967 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.
- 5967
- Problems
- 2210
- Auto-graded
- 15
- Topics
- 272
- Added today
Showing 1–30 of 434 results
- Trees & GraphsHardModel answerConstruct Non-Conflicting Queens Configurations
Compute all possible configurations of n non-attacking queens on an n x n board using stateful depth-first search.
Trees & Graphsbacktrackingrecursiondepth-first-search - Trees & GraphsMediumAuto-gradedStop Listing and Indented Reporting Tree from Raw Inputs
Parse a JSON string into formatted stop lines and turn employee rows into a sorted, indented reporting-tree outline using an adjacency list and iterative DFS.
Trees & Graphsjsontreedfssorting - Trees & GraphsMediumAuto-gradedSmallest-First Course Ordering With Cycle Check
Produce the lexicographically smallest valid course order from prerequisite pairs, or an empty list if a cycle makes it impossible, using a topological sort with a min-heap.
Trees & Graphstopological-sortgraphheapcycle-detection - Trees & GraphsMediumAuto-gradedMinimum Grid Manhattan Distance Between Target Characters
Find the minimum Manhattan distance between any pair of target characters in a 2D character grid.
Trees & Graphsbfsmatrixdistance-transformgraphs - Trees & GraphsHardModel answerGrid Partitioning and Navigating Safe Subregions
Construct a valid contiguous layout for multiple crop zones on a grid and find the shortest path avoiding edge-touching zones.
Trees & Graphstrees-graphsgridbfsconstructive-algorithms - Trees & GraphsHardAuto-gradedDictionary Words Hidden in a Letter Grid
Find every dictionary word that can be traced through adjacent, non-repeating cells of a letter grid, which rewards sharing prefixes across words instead of searching per word.
Trees & Graphstriebacktrackingdfsgrid - Trees & GraphsMediumModel answerGraph Toolkit for Scene and Dependency Graphs: Sort, Traverse, Route
Implement topological sort, BFS, DFS and Dijkstra on a dependency graph, then discuss CSR versus adjacency lists, CPU/GPU parallel traversal, and deterministic testing.
Trees & Graphstopological-sortbfs-dfsdijkstracsr - Trees & GraphsMediumAuto-gradedMinimum Hops Between Two Tasks in a Dependency Graph
Find the fewest directed edges from a start node to a goal node in an acyclic graph, returning 0 for identical nodes and -1 when unreachable; tests BFS on unit-weight graphs.
Trees & Graphsgraphbfsshortest-pathdag - Trees & GraphsMediumAuto-gradedCollect Allowed Values Depth by Depth from a Nested-List Tree
Traverse a binary tree given as nested lists level by level and keep only values from an allowed set, preserving left-to-right order and empty levels.
Trees & Graphsbinary-treelevel-orderbfsstack - Trees & GraphsMediumAuto-gradedGroup Staff Names by Reporting Depth
Turn flat employee-manager records into a list of name groups by depth from the top manager, using a level-by-level breadth-first traversal.
Trees & Graphsbfstreehash-maplevel-order - Trees & GraphsMediumAuto-gradedWeb Crawling Discovery and Bracket Syntax Check
Perform a depth-bounded graph traversal over web pages based on domain filtering, and validate balanced brackets using a stack.
Trees & Graphsbfsgraph-traversalstackstring-validation - Trees & GraphsMediumAuto-gradedFast Power Residue Plus Nearest-Source Grid Map
Combine square-and-multiply modular exponentiation with a multi-source BFS that labels every grid cell with its distance to the nearest source cell.
Trees & Graphsbfsmodular-exponentiationgridmulti-source-bfs - Trees & GraphsMediumAuto-gradedMerge Accounts Into Groups via Weighted Field Matching
Group records into clusters where records are linked when their name/email match score reaches a cutoff, using union-find and bucketing on exact field values.
Trees & Graphsunion-findconnected-componentsgraphhashing - Trees & GraphsMediumAuto-gradedAnticlockwise Perimeter Walk of an Index-Based Binary Tree
Compute the anticlockwise perimeter of a binary tree given as child-index arrays, combining root, left edge, leaves and right edge without duplicates.
Trees & Graphsbinary-treetree-traversaldfsiterative - Trees & GraphsMediumAuto-gradedSmallest-ID Study Order for One Goal Course
Restrict a dependency graph to the ancestors of one goal node, then produce the smallest-ID-first topological order, or an empty list if a cycle blocks it.
Trees & Graphstopological-sortgraphheapcycle-detection - Trees & GraphsEasyModel answerCount Activations per Node in a Cascade Graph
Given a DAG of task dependencies and one start node, compute how many times each node fires when every activation fans out once along every outgoing edge.
Trees & Graphsdagtopological-sortpath-countinggraph-traversal - Trees & GraphsMediumAuto-gradedLandmass Tally: Count Regions and Find the Biggest
Count 4-connected groups of land cells in a binary grid and report the area of the largest group, testing graph traversal with correct visited-state handling.
Trees & Graphsgraphdfsbfsgrid - Trees & GraphsMediumAuto-gradedShortest Word Chain Allowing One or Two Letter Swaps
Find a shortest word chain where each step swaps one or two letters, with a fixed tie-break, using BFS on an implicit graph and wildcard bucketing for fast neighbor lookup.
Trees & Graphsbfsshortest-pathstringshashing - Trees & GraphsMediumAuto-gradedMinimum Rides Across Circular Shuttle Lines
Find the fewest shuttle lines to board to get from one stop to another, using a graph search over lines and a stop-to-lines index to stay linear in total stops.
Trees & Graphsbfsgraphhash-mapshortest-path - Trees & GraphsMediumAuto-gradedEdge Silhouettes of a Level-Order Binary Tree
Build a binary tree from a level-order list with gaps and report the first and last node of every level, testing BFS level separation and level-order parsing.
Trees & Graphsbinary-treebfslevel-ordertree-construction - Trees & GraphsMediumAuto-gradedFewest Rolls to Park a Sliding Ball in a Grid
Model a sliding ball as BFS over resting positions, where each edge is a full roll until a wall or border, and the target counts only if the ball stops on it.
Trees & Graphsbfsgridgraphshortest-path - Trees & GraphsMediumModel answerReconstruct Binary Tree from Inorder and Postorder Sequences
Reconstruct a binary tree given its inorder and postorder traversal arrays, assuming all node values are unique.
Trees & Graphstrees-graphsrecursionhash-table - Trees & GraphsEasyAuto-gradedVerify Root Sequence Match in N-ary Tree
Determine if a given target sequence matches a top-down path in an N-ary tree represented by nested dictionaries.
Trees & Graphstrees-graphsrecursiondfstree-traversal - Trees & GraphsMediumAuto-gradedCounting Separate Land Patches in a 0/1 Grid
Count connected components of 1-cells in a binary grid using only up/down/left/right adjacency, via flood fill or union-find.
Trees & Graphsgraphbfsconnected-componentsmatrix - Trees & GraphsMediumAuto-gradedSmallest-Label Build Sequence with Cycle Check
Produce the lexicographically smallest valid ordering of a dependency graph using a min-heap variant of Kahn's algorithm, returning an empty list if a cycle makes ordering impossible.
Trees & Graphstopological-sortheapgraphcycle-detection - Trees & GraphsMediumAuto-gradedCollect Path-Tagged Errors from a Nested Payload Schema Check
Recursively walk a JSON-like value alongside a simplified schema and report type and missing-key errors with exact paths, in deterministic order.
Trees & Graphsrecursiondfsjsonvalidation - Trees & GraphsMediumAuto-gradedCount Node Changes Between Two Keyed Hierarchies
Compare two keyed trees in parallel and count changed nodes, where a changed value replaces its whole subtree and unmatched nodes count with their subtrees.
Trees & Graphstreedfshash-mapsubtree-size - Trees & GraphsMediumAuto-gradedExtract Text From Matching Elements in Messy Markup
Parse a forgiving HTML string into an element tree in one pass, then collect each matching element's combined text in document order using an iterative depth-first traversal.
Trees & Graphsparsingtreedfsstack - Trees & GraphsMediumAuto-gradedTotal Value of Bit-Strings Along a Tree's Leaf Paths
Decode a level-order bit tree with skipped None slots, then sum the binary values read along each root-to-leaf path, testing BFS parsing and DFS with a running accumulator.
Trees & Graphsbinary-treedfsbfslevel-order-parsing - Trees & GraphsMediumAuto-gradedClosest-Pair Dispatch of Couriers on a Walled Grid
Match couriers to parcels by repeatedly choosing the globally closest pair, using BFS shortest paths on a grid with walls and deterministic tie-breaking.
Trees & Graphsbfsgridgreedysorting