Topic
Trees & Graphs interview problems
Traversals, shortest paths, topological order and union-find. 434 original problems, each with hidden test cases you can run in the browser.
25 easy362 medium47 hard
Showing 151–180 of 434 results
Answer batched queries on a static directed follow graph: list direct followees and rank second-hop accounts by how many followees also follow them.
Auto-gradedgraphhash-mapadjacency-listsortingGroup 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.
Auto-gradedbinary-treebfssortingcoordinatesFind 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.
Auto-gradedgriddijkstrashortest-path0-1-bfsChoose one shift per element from a given list to maximize distinct results; tests recognizing the problem as bipartite matching and implementing Hopcroft-Karp efficiently.
Auto-gradedbipartite-matchinghopcroft-karpgraphsgreedy-pitfallsTraverse a nested directory dictionary depth-first and build the full slash-joined path for each file, following precise joining and ordering rules.
Auto-gradeddfstree-traversalrecursionstringsDesign and implement a React component to display nested JSON with collapsible nodes, indentation, and syntax highlighting for primitive types.
Model answerReactJSONTreeFrontendGroup nodes of a binary tree represented in array heap layout into vertical columns ordered from left to right.
Auto-gradedtrees-graphsbreadth-first-searchbinary-treequeuesEvaluate grid graph connectivity by finding the number of distinct 4-directionally connected land components.
Auto-gradedtrees-graphsdfs-bfsgridCompute 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.
Auto-gradedbfsgridmulti-sourceshortest-pathCheck if a list of integers forms a complete valid root-to-leaf path in a binary tree given as an adjacency table.
Auto-gradedtrees-graphstreearrayGroup 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.
Auto-gradedtriehash-mapstable-sortdfsProcess 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.
Model answertrees-graphsdfscycle-detectiongraph-traversalPerform a flood-fill recoloring on a 2D integer grid while avoiding call stack overflow and preserving the original input.
Auto-gradedbfs-dfsmatrixflood-fillgraph-traversalEvaluate symbolic variable definitions with standard arithmetic precedence, resolving variable dependencies while detecting cycles and missing definitions.
Auto-gradedtrees-graphsstacks-queuestopological-sortrecursionFind 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.
Auto-gradedunion-findconnected-componentsbitmaskgraphFind the minimum travel distance from every destination point to its closest source hub on a 2D grid using multi-source Breadth-First Search.
Auto-gradedBFSMulti-Source BFSGrid TraversalShortest PathEvaluate a split-based arithmetic expression, returning false the moment any literal or intermediate value is non-positive or non-integer.
Model answerrecursionexpression-evaluationpost-orderparsingTests breadth-first search on a square binary grid with eight-directional moves, handling blocked endpoints, visited tracking, and counting cells along the shortest route.
Auto-gradedbfsgridshortest-pathgraph-traversalCombine a merge-style sparse vector dot product with an iterative flood fill that counts 4-connected land clusters, returning both results together.
Auto-gradedtwo-pointerssparse-vectorgriddfsFind the shortest distance between two web pages in a directed link graph using breadth-first search.
Auto-gradedbfsgraphshortest-pathtrees-graphs- Grid Land Mass ValuationMedium
Find all orthogonal connected components of non-zero cells in a 2D grid and calculate the total sum of cell values for each component.
Auto-gradedtrees-graphsbreadth-first-searchdepth-first-searchmatrix 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.
Auto-gradedbinary-search-treedfstree-constructionpruningBuild 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.
Model answerbinary-treeserializationpreorderstackRun 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.
Auto-gradedbfsgridshortest-pathpath-reconstructionFind 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.
Auto-gradedtreedfshash-mapforestProduce 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.
Auto-gradedtopological-sortheapgraphkahn-algorithmOrganize the elements of a binary tree into vertical columns using level-order traversal rules on a level-order array input.
Auto-gradedtrees-graphsbreadth-first-searcharraysqueuesFind 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.
Auto-gradedtrees-graphsdfstree-traversalFind 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.
Model answerlowest-common-ancestorbinary-treedagbfsDetermine the final visited node when following single-successor directed edges until reaching a dead end or a previously visited node.
Auto-gradedtrees-graphsarrayshash-table