practice a little every day — you've got this ♡
Trees & Graphs Interview Problems
Practice 5971 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.
- 5971
- Problems
- 2211
- Auto-graded
- 15
- Topics
- 272
- Added today
Showing 91–120 of 434 results
- Trees & GraphsMediumAuto-gradedMulti-Hop Currency Conversion Over a Rate Table
Compute a conversion factor between two currencies by chaining and inverting listed rates, returning -1.0 when no chain exists; tests graph traversal with multiplicative weights.
Trees & Graphsgraphbfshash-mapweighted-edges - Trees & GraphsMediumAuto-gradedSuggest Top Social Connection
Find the non-adjacent node in an undirected graph with the maximum count of shared neighbors relative to a target node.
Trees & Graphsgraphsbfshash-tablesocial-network - Trees & GraphsHardModel answerShortest Hop Count Through a Flaky Web Graph
Crawl a website graph from a start URL to an exit page using BFS, retrying transient 5xx failures a limited number of times, and return the minimum hop count or -1.
Trees & Graphsbfsgraph-traversalretry-logicvisited-set - Trees & GraphsMediumAuto-gradedFind the Best-Paid Sub-Organization by Mean Pay
Aggregate subtree salary totals and headcounts bottom-up in a tree given as a flat list, then pick the best root using exact average comparison with size and id tie-breaks.
Trees & Graphstreedfspost-ordertie-breaking - Trees & GraphsHardAuto-gradedFewest Planks Across a Portal-Linked Board
Find the cheapest route on a grid with free, paid and blocked cells plus same-numbered teleport cells, which calls for 0-1 BFS and care with teleport expansion.
Trees & Graphs0-1 BFSshortest pathgridgraph modeling - Trees & GraphsMediumAuto-gradedCollect Every Value Stored Under a Key in Nested Data
Walk a nested structure of dicts and lists depth-first and gather every value stored under a given key, in traversal order, including matches inside already-matched values.
Trees & Graphsrecursiondfsjsontraversal - Trees & GraphsMediumAuto-gradedGenerate Preorder Depth Forest from Directed Node Pairs
Construct a hierarchical forest from directed child-parent relations and output a depth-annotated preorder traversal.
Trees & Graphstrees-graphsdepth-first-searchstackrecursion - Trees & GraphsMediumAuto-gradedBest Meeting Cell on a Grid with Walls
Find the open cell with the smallest total shortest-path distance to a set of target cells on a grid with obstacles, using BFS and reachability counting.
Trees & Graphsbfsgridshortest-pathgraph-traversal - Trees & GraphsMediumAuto-gradedTree Depth After Splicing Out Removed Nodes
Compute the depth of a rooted tree given as a parent array after splicing out marked nodes, so their children attach to the nearest surviving ancestor.
Trees & Graphstreebfsparent-arraydepth - Trees & GraphsMediumAuto-gradedBest Multi-Hop Exchange Rate Between Two Currencies
Find the largest product of directed exchange rates along any path between two currencies, using Bellman-Ford-style relaxation on a graph that may contain cycles and rates above 1.
Trees & Graphsgraphbellman-fordshortest-pathcurrency - Trees & GraphsEasyAuto-gradedGrid Zone Coloring Feasibility
Determine whether empty grid plots can be assigned one of k colors without adjacent conflicts.
Trees & Graphstrees-graphsarraysmath-bits - Trees & GraphsMediumAuto-gradedGrid Contagion Simulation
Simulate multi-source BFS propagation across a 2D grid up to a maximum number of steps.
Trees & Graphsbreadth-first-searchmatrixgraph-traversal - Trees & GraphsMediumModel answerTwo Warm-Ups: One-Deletion Palindrome and Column-Grouped Tree Output
Decide whether a string becomes a palindrome after removing at most one character, then group a binary tree's node values by column using level-order tie-breaking.
Trees & Graphstwo-pointerspalindromebfsbinary-tree - Trees & GraphsMediumAuto-gradedEarliest Finish Time for a Dependent Job Pipeline
Compute the shortest total time to finish all jobs with unlimited parallelism by finding the longest weighted path in a dependency graph, returning -1 if a cycle exists.
Trees & Graphstopological-sortdaglongest-pathdynamic-programming - Trees & GraphsMediumAuto-gradedSmallest Valid Order for Dependency Forest
Construct the lexicographically smallest topological ordering of nodes in a forest defined by an ancestor/parent mapping.
Trees & Graphstrees-graphsheaps-sortinggreedy-intervals - Trees & GraphsMediumAuto-gradedFewest Single-Letter Edits Through a Word List
Tests modeling word edits as an implicit graph and running BFS with wildcard buckets to find the minimum number of one-letter changes, with careful edge cases.
Trees & Graphsbfsgraphstringshashing - Trees & GraphsMediumAuto-gradedMaximum Pebble Removals on a Coordinate Board
Compute how many pebbles can be taken off a board when each removal needs another remaining pebble in the same row or column, using connected components.
Trees & Graphsunion-findconnected-componentsgraph-modelingdfs - Trees & GraphsMediumModel answerUnify Contact Profiles Linked by Common Email Addresses
Combine contact records that are directly or transitively linked by a shared email, outputting each person's name with a deduplicated, sorted email list.
Trees & Graphsunion-findgraphconnected-componentsdfs - Trees & GraphsMediumAuto-gradedLongest Chain of Accounts Reachable Through Follows
Find the longest simple path from a start node in a directed graph with possible cycles, using backtracking DFS with a per-path visited set.
Trees & Graphsgraphdfsrecursionbacktracking - Trees & GraphsMediumAuto-gradedFive-Task Toolkit: Graphs, Swaps, Digits, Cache, Trees
Solve five small tasks in one call: count graph components, minimum swaps to sort, largest monotonic number, simulate an LRU cache, and compare two N-ary trees.
Trees & Graphsgraph-traversalcycle-decompositiongreedy-digitslru-cache - Trees & GraphsMediumAuto-gradedTally Separate Clusters of Ones in a Binary Matrix
Count 4-directionally connected clusters of 1s in a binary matrix using graph traversal, with care for visited tracking, empty inputs, and deep clusters.
Trees & Graphsdfsgridconnected-componentsmatrix - Trees & GraphsHardAuto-gradedShortest Looping Command Script for a Fuel-Limited Rover
Brute-force enumerate looping command scripts of length 1 to 10 and simulate each on a grid with fuel, walls and refuel pads, using state-repeat detection to stop loops.
Trees & Graphssimulationbrute-forcegridcycle-detection - Trees & GraphsMediumAuto-gradedRebuild a Nested Menu Tree from Indented Text
Parse an indentation-based, pipe-delimited menu into a nested tree of dictionaries, testing stack-based hierarchy reconstruction and careful field parsing.
Trees & Graphstree-constructionstackparsingstrings - Trees & GraphsEasyAuto-gradedNearest Node in a Binary Search Tree
Find the value in a Binary Search Tree represented as a level-order array that has the smallest absolute difference to a target number.
Trees & Graphstrees-graphsbinary-search-treesearch - Trees & GraphsMediumAuto-gradedFewest Moves Through a Walled Maze
Compute the minimum number of 4-directional moves between two open cells of a binary maze, or -1 if unreachable; tests breadth-first search on an implicit grid graph.
Trees & Graphsbfsgridshortest-pathgraph - Trees & GraphsHardModel answerFastest Route Through Only the Courses a Goal List Needs
Given courses with durations, prerequisite links and a list of goal courses, compute the minimum time to finish the goals and their needed prerequisites, as total effort and as elapsed time.
Trees & Graphsgraphtopological-sortdagcycle-detection - Trees & GraphsMediumAuto-gradedValidate Binary Tree from Directed Edge List
Evaluates tree properties, cycle detection, edge validity, and in-order traversal under strict error precedence.
Trees & Graphstreesgraphsdfstraversal - Trees & GraphsMediumModel answerBuild a Display Order for Tasks with Dedup, Filtering and Subtasks
Turn a flat batch of scheduler tasks into a display list: merge duplicates, hide finished work, order by priority, and keep each subtask right under its parent.
Trees & Graphssortinghashingtree-traversalcycle-detection - Trees & GraphsMediumModel answerDistributed Tree Traversal and Reliable Neighbor Messaging Protocol
Design a reliable message passing protocol across adjacent tree nodes, then compute total network size and discover paths under network faults.
Trees & Graphstrees-graphsdistributed-systemsmessage-passingnetwork-protocol - Trees & GraphsMediumModel answerModeling Classic Puzzles: River Crossing, Jugs, and Proofs
Turn a set of contest-style logic puzzles, led by the fox-chicken-grain river crossing, into formal models, and give algorithms with proofs of correctness and optimality.
Trees & Graphsbfsstate-space-searchinvariantsproofs