practice a little every day — you've got this ♡
Trees & Graphs Interview Problems
Practice 5969 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.
- 5969
- Problems
- 2211
- Auto-graded
- 15
- Topics
- 273
- Added today
Showing 61–90 of 434 results
- Trees & GraphsMediumAuto-gradedMinesweeper Tap: Flood-Reveal Safe Cells and Show Mine Counts
Simulate one Minesweeper tap on a grid, flood-revealing connected zero-count cells with an iterative traversal and labelling border cells with their 8-neighbour mine counts.
Trees & Graphsbfsflood-fillgridmatrix - Trees & GraphsMediumAuto-gradedDensest Graph Without Triangles: Count and Build
Find the largest edge count of a triangle-free simple graph on n vertices and output a canonical extremal graph, testing Mantel's theorem and the complete bipartite construction.
Trees & Graphsgraph-theoryconstructionbipartitemantel-theorem - Trees & GraphsMediumAuto-gradedDiff Two Versions of a Keyed Hierarchy
Compare two keyed N-ary trees given as nested dicts and count nodes that were added, removed, given a new value, or attached to a different parent.
Trees & Graphstreehash-mapdfstree-diff - Trees & GraphsMediumAuto-gradedLexicographically Smallest Valid Task Schedule
Decide whether tasks with prerequisite constraints can all be run, and if so produce the lexicographically smallest valid run order, using topological sorting with a min-heap.
Trees & Graphstopological-sortgraphheapcycle-detection - Trees & GraphsMediumAuto-gradedRank Suggested Connections by Shared Friends
Build an undirected graph from friendship pairs, then rank every non-friend of a target user by mutual friends, degree and ID using a composite sort key.
Trees & Graphsgraphadjacency-listsortingsets - Trees & GraphsMediumAuto-gradedSchedule Courses Under Prerequisite Rules
Produce a deterministic course order that respects prerequisite pairs using a queue-based topological sort, or an empty list if the prerequisites contain a cycle.
Trees & Graphstopological-sortgraphbfscycle-detection - Trees & GraphsEasyAuto-gradedNearest Shared Ancestor in an Array-Encoded Binary Tree
Find the deepest node that is an ancestor of two given values in a binary tree stored as a heap-indexed array, using a parent map and ancestor walk.
Trees & Graphsbinary-treelowest-common-ancestorbfshash-map - Trees & GraphsHardAuto-gradedSchedule Tasks with Precedence Constraints
Determine a valid sequential execution order for a set of tasks given dependency rules, or detect impossible circular dependencies.
Trees & Graphstopological sortgraphbfsdegree count - Trees & GraphsEasyModel answerBinary Tree Lateral Perspective and Zero-Sum Triplet Extraction
Solve two fundamental interview tasks: identifying the rightmost nodes of a binary tree by level and finding non-duplicate zero-sum triplets in an un-ordered array.
Trees & Graphsbinary-treebfstwo-pointerssorting - Trees & GraphsMediumAuto-gradedHub Node Pair Counting on a Weighted Tree with Divisible Distances
Count, for each node of a weighted tree, the unordered pairs of other nodes at distances divisible by k and lying in different branches around that node.
Trees & Graphstreedfscountingcombinatorics - Trees & GraphsMediumAuto-gradedCluster Counting on a Grid with King-Move Adjacency
Count groups of touching 1-cells in a binary grid where all eight surrounding cells count as neighbors, testing grid traversal and connected-component counting.
Trees & Graphsgridbfsconnected-componentsmatrix - Trees & GraphsMediumAuto-gradedRight-Triangle Distance Vertices in a Tree
Compute distances in a tree from three marked vertices and count the other vertices whose three distances form a right-triangle (Pythagorean) triple.
Trees & Graphsbfstreegraph-traversalmath - Trees & GraphsMediumModel answerRobot Navigation on a Hidden Grid with DFS and Backtracking
Guide a robot through a map it can only discover step by step, reaching the target with no repeated visits, real backtracking, and a clear result when the target is unreachable.
Trees & Graphsdfsbacktrackinggraph-traversalgrid - Trees & GraphsEasyAuto-gradedLocate the Universally Followed Silent Guest
Find the one node in a directed relation that everyone points to and that points to nobody, using a linear elimination pass followed by verification.
Trees & Graphsgraphcelebrity-problemtwo-passelimination - Trees & GraphsMediumAuto-gradedTeardown Sequencing with Nested Ownership and Extra Prerequisites
Find the lexicographically smallest valid ordering of nodes under child-before-parent and extra precedence rules, or report impossibility when the rules contradict.
Trees & Graphstopological-sortheapcycle-detectiongraph - Trees & GraphsMediumModel answerSliding Block Minimums and Dependency-Ordered Cooking Plan
Compute the minimum of every K x K window in a grid, then order recipes so that every derived ingredient is made before the dish that uses it, detecting cycles.
Trees & Graphstopological-sortmonotonic-dequesliding-windowkahns-algorithm - Trees & GraphsMediumAuto-gradedSemester Planner: Build a Valid Course Sequence
Produce a deterministic topological ordering of courses from prerequisite pairs, or an empty list when a circular requirement makes it impossible.
Trees & Graphstopological-sortgraphbfscycle-detection - Trees & GraphsMediumModel answerFind a Money-Making Loop in a Table of Exchange Rates
Given directed currency exchange quotes, decide whether some round trip returns more than it started with, and output one such round trip as an ordered list of currencies.
Trees & Graphsgraphbellman-fordnegative-cyclefloating-point - Trees & GraphsMediumAuto-gradedEarliest Safe Starting Cell in a Jump Array
Find the smallest start index in a jump array whose walk never goes below index 0, handling cycles and right exits, ideally in linear time.
Trees & Graphsfunctional-graphcycle-detectionmemoizationarrays - Trees & GraphsMediumAuto-gradedRoute Between Two Nodes of an Implicit Recursive Tree
Find the unique path between two pre-order-indexed nodes in a huge recursively defined tree, using subtree sizes to navigate without building it.
Trees & Graphstreelcarecursionpre-order - Trees & GraphsMediumAuto-gradedStrongest Signal Route in a Lossy Link Network
Find the route between two nodes in an undirected graph that maximizes the product of per-link delivery probabilities, using a Dijkstra-style search with a max-priority queue.
Trees & Graphsgraphdijkstraheapshortest-path - Trees & GraphsMediumAuto-gradedBalanced BST Level-Order Output from a Sorted Sequence
Build a height-balanced BST from a sorted list using a fixed middle-element rule, then serialize it level by level with null placeholders.
Trees & Graphsbinary-search-treedivide-and-conquerrecursionlevel-order-traversal - Trees & GraphsMediumAuto-gradedLocked Gates Grid: Fewest Steps With Collected Keys
Find the fewest moves through a grid where lowercase cells give keys and uppercase cells are gates, using BFS over position plus the set of collected keys.
Trees & Graphsbfsgridstate-space-searchkeys-and-doors - Trees & GraphsMediumAuto-gradedReconstruct Hierarchical Execution Trees from Trace Records
Reassemble an unordered collection of trace span objects into a forest of child-linked execution trees sorted chronologically.
Trees & Graphstreeshash-tablesortinggraph - Trees & GraphsEasyAuto-gradedGroup Hierarchy Members by Depth Level
Construct an adjacency graph from reporting links and perform a level-order traversal to group node IDs by depth.
Trees & Graphstrees-graphsbfshash-map - Trees & GraphsMediumAuto-gradedBest Plot After Reclaiming a Single Water Tile
Find the largest connected land region achievable by turning at most one water cell into land, which tests component labeling and merging neighbors without double counting.
Trees & Graphsgridflood-fillconnected-componentsdfs - Trees & GraphsMediumAuto-gradedTwo Teams With Rival Pairs Kept Apart
Decide whether a set of people can be placed into two teams so that no rival pair shares a team, which tests graph 2-coloring across possibly disconnected components.
Trees & Graphsgraphbipartitebfscoloring - Trees & GraphsMediumAuto-gradedRender a Nested Folder Structure as Indented Lines
Traverse a nested dictionary tree in pre-order, tracking depth to build indented lines with a fixed marker, preserving the given child order.
Trees & Graphstree-traversaldfsstackstrings - Trees & GraphsMediumAuto-gradedCan Every Module in a Study Plan Be Finished?
Decide whether a set of ordering rules between numbered modules contains a circular dependency, by detecting a cycle in a directed graph.
Trees & Graphsgraphtopological-sortcycle-detectionbfs - Trees & GraphsMediumAuto-gradedMinimum Degrees of Separation in a Social Network
Determine the shortest path distance between two nodes in an unweighted, undirected graph using Breadth-First Search.
Trees & Graphsbfsgraphshortest-pathhash-map