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 31–60 of 434 results
- Trees & GraphsMediumAuto-gradedFind the k-th Value in a Level-Order Encoded Tree's Inorder Sequence
Decode a level-order binary tree with null gaps, then return the k-th value in its inorder sequence, or -1 if fewer than k nodes exist.
Trees & Graphsbinary-treeinorder-traversaliterative-traversalstack - Trees & GraphsMediumAuto-gradedInherited Permissions Across a Group Hierarchy
Answer permission queries over a DAG of groups where each group inherits from its parents, using graph traversal with memoization or caching.
Trees & Graphsgraphdagdfsmemoization - Trees & GraphsMediumAuto-gradedBest Hub-and-Spokes Value Sum with a Spoke Limit
Choose a hub node and up to k adjacent nodes to maximize the total node value, which tests per-node greedy selection over adjacency lists.
Trees & Graphsgraphgreedysortingadjacency-list - Trees & GraphsMediumAuto-gradedReach the Goal State While Avoiding Forbidden Nodes
Decide whether a goal node can be reached from node 0 in a directed graph without ever stepping on a forbidden node, using BFS or DFS reachability.
Trees & Graphsgraphbfsreachabilitydirected-graph - Trees & GraphsMediumAuto-gradedFirst Moment a Cable Network Becomes One Piece
Replay unsorted timed link events and find the earliest timestamp at which every node is in one connected group, using union-find over events sorted by time.
Trees & Graphsunion-findgraph-connectivitysortingkruskal - Trees & GraphsMediumAuto-gradedIndented Staff Listing from Direct-Report Pairs
Build a forest from (employee, manager) pairs and output each person with their depth in a sorted depth-first order, handling very deep chains iteratively.
Trees & Graphstreedfsforesthash-map - Trees & GraphsMediumAuto-gradedSplit a Nested Structure into Values and a Shape Template
Implement a single function that extracts leaves and a shape template from nested lists and dicts, then rebuilds the original from them, testing recursion and traversal order.
Trees & Graphsrecursiondfsnested-structuresdictionaries - Trees & GraphsMediumModel answerIdentify Node Value Present Across Most Depth Levels
Find the binary tree node value that appears across the highest number of unique depth levels.
Trees & Graphstrees-graphsbreadth-first-searchhash-table - Trees & GraphsEasyAuto-gradedDistance Map to the Closest Exit in a Maze Grid
Compute, for every cell of a grid with walls and exits, the fewest steps to the nearest exit, marking walls and cut-off cells as -1, using multi-source BFS.
Trees & Graphsbfsgridmulti-source-bfsshortest-path - Trees & GraphsHardModel answerRegion-Splitting Tree and Multi-Word Grid Search
Compress a square character grid into a four-way region tree, then locate a batch of words in the grid by walking neighbors in eight directions without reusing cells.
Trees & Graphsquadtreetriebacktrackingdivide-and-conquer - Trees & GraphsMediumAuto-gradedFastest Route Time Through a One-Way Street Network
Find the minimum total cost between two nodes of a directed graph with non-negative edge weights, returning -1 if no route exists. Tests shortest-path reasoning with a priority queue.
Trees & Graphsdijkstrashortest-pathgraphheap - Trees & GraphsMediumAuto-gradedSort a List and Replay Commands on a Binary Search Tree
Sort an integer list without built-in sorting, then run a script of insert, search, delete and in-order commands on a duplicate-free binary search tree built from scratch.
Trees & Graphsbinary-search-treequicksortrecursiontree-deletion - Trees & GraphsMediumAuto-gradedSplit Nodes Into Two Groups With No Internal Links
Decide whether the vertices of an undirected multigraph can be split into two groups so every edge crosses between them, handling self-loops, repeated edges, and isolated nodes.
Trees & Graphsgraphbfsbipartiteconnected-components - Trees & GraphsMediumAuto-gradedFastest Signal Arrival Times Across a Relay Grid
Compute shortest-path distances from one source in an undirected graph with non-negative weights, handling parallel edges, self-loops, and unreachable nodes.
Trees & Graphsdijkstrashortest-pathgraphheap - Trees & GraphsHardAuto-gradedDistinct Transitive Prerequisites in a Dependency DAG
For each node in a DAG whose links may name unknown items, count the distinct nodes reachable along link direction, counting shared descendants once.
Trees & Graphsgraphdagtopological-sortbitset - Trees & GraphsMediumAuto-gradedDoes This One-Way Network Contain a Loop?
Decide whether a directed graph given as an adjacency list contains a cycle, handling self-loops, parallel edges, disconnected parts and an empty graph.
Trees & Graphsgraphdirected-graphcycle-detectiontopological-sort - Trees & GraphsMediumModel answerMapping a Hidden Maze: Shortest Route for a Sensing Robot
A robot in an unseen grid senses neighbours for free and pays per move. Find a shortest route to a target, or return to the start and report failure if none exists.
Trees & Graphsbfsgridonline-explorationshortest-path - Trees & GraphsMediumModel answerRight Edge of a Tree and Minimal Bracket Removal
Two linked tasks: list the nodes visible from the right of a binary tree, and delete the fewest parentheses from a string so the rest is balanced.
Trees & Graphsbinary-treebfsstackstrings - Trees & GraphsMediumAuto-gradedNegative Loop Reachable From a Source Vertex
Decide whether a weighted directed graph has a negative-total cycle reachable from a given source vertex, using Bellman-Ford while ignoring unreachable regions.
Trees & Graphsgraphsbellman-fordnegative-cycleshortest-path - Trees & GraphsMediumAuto-gradedFind a Word Spanning the Fragments at a Tree's Leaves
Stream the leaf strings of a binary tree in left-to-right order and decide whether a pattern occurs in their concatenation, without ever building the full text.
Trees & Graphsbinary-treekmpstring-matchingiterative-dfs - Trees & GraphsMediumAuto-gradedRecover a Letter Ordering from a Sorted Word List
Derive precedence constraints between letters from adjacent sorted words, then topologically sort them while detecting contradictions and invalid prefix orderings.
Trees & Graphstopological-sortgraphstringscycle-detection - Trees & GraphsMediumAuto-gradedTallest Chain of Nodes in an Index-Linked Binary Tree
Compute the height of a binary tree given as a child-index table, handling empty input and very deep skewed trees without recursion failures.
Trees & Graphsbinary-treedfsiterative-traversaltree-height - Trees & GraphsMediumAuto-gradedCounting Land Clusters on a Wrap-Around Map
Count connected groups of land cells on a grid whose opposite edges wrap around, testing grid traversal with modular adjacency.
Trees & Graphsgraphdfsgridunion-find - Trees & GraphsMediumModel answerFriend Product Suggestions and Click-Path Reachability
Two short coding tasks: suggest products that a user's friends bought but the user hasn't, and decide whether one URL can reach another through recorded navigation steps.
Trees & Graphshash-setset-differencegraphbfs - Trees & GraphsMediumAuto-gradedUnlock Order: Build a Dependency-Respecting Study Plan
Produce a deterministic topological ordering of nodes from prerequisite pairs, or an empty list if a cycle makes it impossible. Tests graph modeling and Kahn's algorithm.
Trees & Graphstopological-sortgraphbfscycle-detection - Trees & GraphsMediumModel answerResolve Variables from Linked Assignment Rules with Cycle Checks
Evaluate a target variable from a list of assignment strings, growing from simple aliasing to signed sums of variables and integers, then detect circular dependencies safely.
Trees & Graphsparsingmemoizationdfscycle-detection - Trees & GraphsMediumAuto-gradedGather Unique Items Across a Linked Collection Graph
Run a breadth-first traversal over a directed graph of folders, emitting each item once in first-seen order, while validating every reference and handling cycles.
Trees & Graphsbfsgraphhash-setdeduplication - Trees & GraphsMediumAuto-gradedLevel-by-Level Site Walk With Failing Pages and a Fetch Cap
Compute a deterministic level-ordered listing of every page reachable from a start page, where failed pages yield no links and concurrency limits must not change the result.
Trees & Graphsbfsgraphlevel-ordersets - Trees & GraphsMediumAuto-gradedFewest Hops from a Start Node While Avoiding Closed Nodes
Run a breadth-first search on a directed or undirected graph, skipping closed nodes, to get each node's minimum edge count from the start, or -1 if it cannot be reached.
Trees & Graphsbfsgraphshortest-pathreachability - Trees & GraphsMediumAuto-gradedIdentify Cycles in Linear Chains and Directed Networks
Detect structural loops in both a next-pointer chain using constant space and a directed graph reachable from a given entry point.
Trees & Graphstrees-graphslinked-listsdfstwo-pointers