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 271–300 of 434 results
Transform a flat array of comments into a sorted, nested, filterable tree while persisting the user's sort preference across sessions.
Model answertree-constructiondfslocalStoragefrontend-dataTests whether a candidate can exploit BST ordering to locate the deepest node that is an ancestor of both targets without searching the entire tree.
Auto-gradedbinary-search-treelowest-common-ancestortree-traversalTests understanding of binary tree traversal by computing boundary nodes at each depth using both breadth-first and depth-first strategies.
Auto-gradedbinary-treebfsdfstree-traversalTests implementation of connected-component search in grids, efficient median computation across sorted sequences, and breadth-first and depth-first graph traversals.
Auto-gradedgraphsarraysbinary-searchbfsTests building a tree structure from unordered edge list by tracking node relationships and identifying the root.
Auto-gradedtreeshash-tablegraph-constructionTests prefix-sum balancing for binary arrays and depth-first search for strictly increasing root-to-leaf paths in binary trees.
Auto-gradedtreesarraysprefix-sumdfsRecursively scan a directory tree, group files by size then content hash, and return every set of two or more paths that hold identical bytes.
Model answerhashingfile-systemtraversaldeduplicationGiven a tree as an adjacency list, return the sequence of nodes forming its diameter — the longest simple path between any two nodes.
Model answerBFSDFStree diameterpath reconstructionTests whether you can model exchange rates as a weighted directed graph and apply Bellman-Ford to detect a cycle whose rate product exceeds 1.
Auto-gradedgraphsbellman-fordlogarithmsTests BFS on an undirected graph to filter nodes by shortest-path distance and a secondary inventory condition, including edge-case handling for missing keys and duplicates.
Auto-gradedbfsgraphsshortest-pathTests iterative functional-graph traversal: propagating True/False through chains of references and NOT, while correctly marking cycles, dangling references, and their dependents as unresolvable.
Auto-gradedgraph traversalcycle detectionhash mapTraverse nested dictionaries and lists to collect dot-and-bracket paths to all string values, returned in sorted order.
Auto-gradedtree-traversaliterationstackpath-buildingParse a LeetCode-style level-order array and return values grouped into nested lists by depth, preserving left-to-right order.
Auto-gradedtreesbfsarraysTests tree traversal, ancestor queries, and handling multiple input formats with a custom precedence rule.
Auto-gradedtreeslowest-common-ancestorgraph-traversalTests multi-source BFS on a grid to propagate shortest walking distances from all exits simultaneously to every reachable empty room.
Auto-gradedbfsgraphsgridTests whether a candidate can traverse an unordered weighted tree in linear time to extract the root, the heaviest root-to-leaf path weight, and the maximum depth.
Auto-gradedtrees-graphshash-mapiterative-dfsGiven an undirected tree and multiple permutations of its nodes, determine for each permutation whether it could be the dequeue order of some BFS starting at its first element.
Model answerBFStreessimulationhashingTraverse a binary tree stored in heap-index layout to find every node whose subtree is height-balanced, returning each with its tree level.
Model answerbinary-treepost-orderheap-layoutbottom-upTests binary search on a monotone feasibility predicate combined with multi-source BFS and Chebyshev distance geometry on a 2-D grid.
Auto-gradedbfsbinary-searchgridTests recursive spatial subdivision (quadtree construction) and graph cycle detection (identifying nodes that always terminate).
Auto-gradedrecursiongraphsdivide-and-conquertopological-sortTests ability to traverse nested data structures and transform hierarchical key-value pairs into a flat representation using path notation.
Auto-gradedrecursioniterationdictionarytree-traversalGiven a grid with depot cells, find shortest paths from query locations to any depot, then extend to pick the depot maximizing a distance-penalized load score.
Model answerBFSDijkstramulti-sourcegridBucket level-order tree nodes by column, then sort each column by depth and value to produce the grouped output.
Auto-gradedbinary-treebreadth-first-searchsortinghash-mapTests ability to find connected components in an undirected graph and compute the maximum difference between the highest and lowest node labels in any single component.
Auto-gradedunion-findgraphsconnected-componentsTests BFS-based shortest-path traversal on an undirected graph, including path reconstruction and degree-of-separation counting with correct edge-case handling.
Auto-gradedgraphsBFSshortest-pathGiven a DAG where each node carries allow and deny lists, compute every node's effective permissions by inheriting and merging rules along edges in topological order.
Model answergraphstopological-sortpermissionsDAGGiven preorder and inorder traversal arrays of a binary tree with unique values, reconstruct the tree in O(n) time and O(n) space.
Model answerbinary-treerecursionhash-maptraversalBuild a validated org-chart tree from manager–report pairs and find the deepest node that is an ancestor of every node in a given set.
Model answerlowest-common-ancestorbinary-liftingtree-traversalinput-validationGiven a list of words, merge them into one string by joining where each word's last letter matches the next word's first letter, dropping the duplicate.
Model answereulerian-pathgraphstringshierholzerTests graph traversal skills by counting connected components in a character grid where land cells are neighbours in all eight directions including diagonals.
Auto-gradedgraph traversalBFS/DFSflood fillconnected components