practice a little every day — you've got this ♡
Trees & Graphs Interview Problems
Practice 5974 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.
- 5974
- Problems
- 2212
- Auto-graded
- 15
- Topics
- 269
- Added today
Showing 151–180 of 434 results
- Trees & GraphsMediumAuto-gradedFollow Graph: Following Lists and Mutual-Count Suggestions
Answer batched queries on a static directed follow graph: list direct followees and rank second-hop accounts by how many followees also follow them.
Trees & Graphsgraphhash-mapadjacency-listsorting - Trees & GraphsMediumAuto-gradedColumn-by-Column Readout of a Binary Tree from Level-Order Input
Group binary tree nodes by horizontal column, ordering each column by depth and then by value, with the tree given as a level-order list with nulls.
Trees & Graphsbinary-treebfssortingcoordinates - Trees & GraphsMediumAuto-gradedCheapest Dungeon Escape Through Monster Cells
Find the minimum number of monster cells entered on any route from start to exit in a grid with walls, using a weighted shortest-path search such as Dijkstra or 0-1 BFS.
Trees & Graphsgriddijkstrashortest-path0-1-bfs - Trees & GraphsHardAuto-gradedMost Distinct Values After Shifting Each Element
Choose one shift per element from a given list to maximize distinct results; tests recognizing the problem as bipartite matching and implementing Hopcroft-Karp efficiently.
Trees & Graphsbipartite-matchinghopcroft-karpgraphsgreedy-pitfalls - Trees & GraphsEasyAuto-gradedCollect Every File Path from a Nested Directory Tree
Traverse a nested directory dictionary depth-first and build the full slash-joined path for each file, following precise joining and ordering rules.
Trees & Graphsdfstree-traversalrecursionstrings - Trees & GraphsMediumModel answerBuild a Collapsible JSON Tree Renderer in React
Design and implement a React component to display nested JSON with collapsible nodes, indentation, and syntax highlighting for primitive types.
Trees & GraphsReactJSONTreeFrontend - Trees & GraphsMediumAuto-gradedGroup Binary Tree Nodes into Vertical Columns
Group nodes of a binary tree represented in array heap layout into vertical columns ordered from left to right.
Trees & Graphstrees-graphsbreadth-first-searchbinary-treequeues - Trees & GraphsMediumAuto-gradedCount Separate Land Masses in a Grid
Evaluate grid graph connectivity by finding the number of distinct 4-directionally connected land components.
Trees & Graphstrees-graphsdfs-bfsgrid - Trees & GraphsMediumAuto-gradedSpreading Pop Wave Across a Square Balloon Grid
Compute the earliest time each cell of a square grid is reached by a wave spreading from several seed cells, using multi-source breadth-first search.
Trees & Graphsbfsgridmulti-sourceshortest-path - Trees & GraphsMediumAuto-gradedVerify Root-to-Leaf Sequence in Binary Tree
Check if a list of integers forms a complete valid root-to-leaf path in a binary tree given as an adjacency table.
Trees & Graphstrees-graphstreearray - Trees & GraphsMediumAuto-gradedMerge Per-User Action Sequences into a Counted Prefix Tree
Group event records by user, order each user's events by time, merge the sequences into a prefix tree with distinct-user counts, and print it in a fixed preorder format.
Trees & Graphstriehash-mapstable-sortdfs - Trees & GraphsMediumModel answerAnalyze Referral Chains and Detect Graph Cycles
Process referral relationships with at most one parent per user. Detect cycles, extract acyclic prefixes, and compute root ancestors and depths for all users in O(n) total time.
Trees & Graphstrees-graphsdfscycle-detectiongraph-traversal - Trees & GraphsMediumAuto-gradedPerform Connected Component Recolor on Grid
Perform a flood-fill recoloring on a 2D integer grid while avoiding call stack overflow and preserving the original input.
Trees & Graphsbfs-dfsmatrixflood-fillgraph-traversal - Trees & GraphsMediumAuto-gradedEvaluate Variable Expressions with Dependencies
Evaluate symbolic variable definitions with standard arithmetic precedence, resolving variable dependencies while detecting cycles and missing definitions.
Trees & Graphstrees-graphsstacks-queuestopological-sortrecursion - Trees & GraphsEasyAuto-gradedLargest Cluster of Two-Digit Numbers Linked by Common Digits
Find the largest connected cluster in a list of two-digit numbers where links come from shared digits, testing graph connectivity modeling with union-find or digit-hub nodes.
Trees & Graphsunion-findconnected-componentsbitmaskgraph - Trees & GraphsMediumAuto-gradedShortest Grid Path to Nearest Fulfillment Hub
Find the minimum travel distance from every destination point to its closest source hub on a 2D grid using multi-source Breadth-First Search.
Trees & GraphsBFSMulti-Source BFSGrid TraversalShortest Path - Trees & GraphsMediumModel answerValidate-As-You-Go Calculator with Positive Integer Results
Evaluate a split-based arithmetic expression, returning false the moment any literal or intermediate value is non-positive or non-integer.
Trees & Graphsrecursionexpression-evaluationpost-orderparsing - Trees & GraphsMediumAuto-gradedMinimum Steps Across a Square Maze with Diagonal Moves
Tests breadth-first search on a square binary grid with eight-directional moves, handling blocked endpoints, visited tracking, and counting cells along the shortest route.
Trees & Graphsbfsgridshortest-pathgraph-traversal - Trees & GraphsMediumAuto-gradedSparse Vector Overlap Sum and Land Cluster Counter
Combine a merge-style sparse vector dot product with an iterative flood fill that counts 4-connected land clusters, returning both results together.
Trees & Graphstwo-pointerssparse-vectorgriddfs - Trees & GraphsMediumAuto-gradedMinimum Web Page Hop Distance
Find the shortest distance between two web pages in a directed link graph using breadth-first search.
Trees & Graphsbfsgraphshortest-pathtrees-graphs - Trees & GraphsMediumAuto-gradedGrid Land Mass Valuation
Find all orthogonal connected components of non-zero cells in a 2D grid and calculate the total sum of cell values for each component.
Trees & Graphstrees-graphsbreadth-first-searchdepth-first-searchmatrix - Trees & GraphsMediumAuto-gradedSum of Keys Within a Value Window in a Serialized BST
Rebuild a BST from a level-order list and sum the node values inside an inclusive range, using ordering to skip subtrees that cannot contain qualifying values.
Trees & Graphsbinary-search-treedfstree-constructionpruning - Trees & GraphsHardModel answerTree to String and Back: A Lossless Binary Tree Codec
Build a pair of functions that flatten a binary tree of integers into a string and restore the identical tree from that string, with a clear format and a correctness argument.
Trees & Graphsbinary-treeserializationpreorderstack - Trees & GraphsHardAuto-gradedClimbing Routes From the Corner: Batch Lookup of Shortest Paths
Run one BFS from the top-left cell of a grid with distinct values, using strictly increasing moves, then answer many target queries by rebuilding paths from stored parent links.
Trees & Graphsbfsgridshortest-pathpath-reconstruction - Trees & GraphsMediumAuto-gradedHide Flagged Comment Threads for a Pet-Preference Reader
Find all comments hidden from a reader when any flagged comment hides its whole reply subtree, handling unordered input, dangling parent IDs, and very deep chains.
Trees & Graphstreedfshash-mapforest - Trees & GraphsMediumAuto-gradedAlphabetical Job Scheduler with Prerequisite Rules
Produce a full run order for jobs under prerequisite constraints, always picking the alphabetically smallest available job, or return an empty list if a cycle exists.
Trees & Graphstopological-sortheapgraphkahn-algorithm - Trees & GraphsMediumAuto-gradedVertical Column Grouping of Array-Represented Binary Trees
Organize the elements of a binary tree into vertical columns using level-order traversal rules on a level-order array input.
Trees & Graphstrees-graphsbreadth-first-searcharraysqueues - Trees & GraphsMediumAuto-gradedFind k-th Subordinate in Cascade Traversal
Find the k-th node reached during a preorder depth-first traversal of a specific node's subtree when children are visited in ascending numerical order.
Trees & Graphstrees-graphsdfstree-traversal - Trees & GraphsMediumModel answerShared Ancestors: Binary Tree to Multi-Parent Graph
Find the lowest common ancestor of two nodes in a binary tree, then generalize to a directed acyclic graph where several incomparable lowest common ancestors can exist.
Trees & Graphslowest-common-ancestorbinary-treedagbfs - Trees & GraphsEasyAuto-gradedTrace Path to Terminal Node or Cycle Entry
Determine the final visited node when following single-successor directed edges until reaching a dead end or a previously visited node.
Trees & Graphstrees-graphsarrayshash-table