KatInterview

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.

Problems434

25 easy362 medium47 hard

Showing 331–360 of 434 results

  • Tests multi-source BFS to find an empty cell minimizing total shortest-path distance to all targets on a grid with obstacles.

    Auto-gradedbreadth-first-searchgraphsgrid-traversal
  • Tests directed graph traversal, Eulerian path construction, and lexicographical ordering with Hierholzer's algorithm.

    Auto-gradedgraphsdfseulerian-pathbacktracking
  • Tests ability to traverse a nested schema definition, flatten heterogeneous check results, and enforce a consistent empty-list contract across all node types.

    Auto-gradedrecursionschema-validationflattening
  • Tests BFS traversal with directional output reversal per level without corrupting the queue structure.

    Auto-gradedbfsbinary-treelevel-orderqueue
  • Tests graph modeling of multiplicative relationships and pathfinding to derive transitive ratios between variables.

    Auto-gradedgraphbfsunion-find
  • Build a recursive evaluator for filter expressions with logical operators and field comparisons, testing tree traversal and nested field lookup.

    Auto-gradedrecursiontreesdictionaries
  • Implement binary search on a monotone predicate, BFS for state-space and grid shortest paths, and random board generation with adjacency counting.

    Model answerbinary-searchbfsshortest-pathgraph-traversal
  • Test whether a breadth-first list representation of a binary tree satisfies strict BST ordering without allowing duplicate values.

    Auto-gradedbinary-treebstvalidation
  • Tests BFS-based shortest-path reasoning on an unweighted 2D grid with blocked cells and 4-directional movement.

    Auto-gradedbfsgraph traversalgridshortest path
  • Build a function that classifies propositions as definitely true, definitely false, or undetermined given a set of facts and implication rules.

    Model answergraphimplication2-SATDFS
  • Tests recursive validation of nested dictionaries against a schema with type and presence requirements.

    Auto-gradedrecursionvalidationnested-structures
  • Tests directed graph construction, cycle detection via Kahn's algorithm, and deterministic tie-breaking with a min-heap to produce the lexicographically smallest valid ordering.

    Auto-gradedtopological-sortgraphsheaps
  • Tests connected-component detection in grids with boundary constraints using BFS or DFS traversal.

    Auto-gradedbfsdfsconnected-componentsgrid-traversal
  • Tests recursion, dictionary traversal, and string formatting to produce an indented tree structure with box-drawing connectors.

    Auto-gradedrecursiontree-traversalstringsformatting
  • Tests whether a candidate can use post-order traversal to handle cascading leaf deletions in a binary tree encoded as a level-order list.

    Auto-gradedbinary-treepost-order-traversalrecursiontree-serialization
  • Tests implicit heap-tree traversal, subtree identification via index arithmetic, and stable compaction without mutating the input array.

    Auto-gradedtrees-graphsarraysbfs-dfs
  • Tests ability to implement BFS on an undirected unweighted graph stored as an adjacency matrix to find the fewest edges between two nodes.

    Auto-gradedgraphsbfsadjacency-matrix
  • Tests bipartite graph traversal and BFS to find shortest paths alternating between items and their containing collections.

    Auto-gradedgraph-theorybfsbipartite-graph
  • Tests ability to detect cycles in a directed graph using DFS-based cycle detection, modelling package dependencies where a cycle makes installation impossible.

    Auto-gradedgraphscycle detectiondepth-first searchtopological order
  • Tests binary search on answer combined with multi-source BFS and 2D prefix sums to optimally place one relay node and minimize the maximum Chebyshev coverage distance.

    Auto-gradedbinary-searchbfsmatrixprefix-sums
  • Tests BFS/DFS connected-components traversal on a 2D grid to locate distinct filled regions and compute the tightest enclosing rectangle for each.

    Auto-gradedbfsdfsconnected-componentsgrid
  • Tests BFS/Dijkstra on an augmented state space where position must be combined with a key-collection bitmask, and directional arrow tiles enforce constrained traversal.

    Auto-gradedbfsdijkstrabitmaskgrid
  • Navigate a robot through an unmapped grid with obstacles using only movement and turn commands to locate a target cell.

    Model answerdfsbacktrackinggraph-traversalsimulation
  • Find the minimum moves for a Chinese-chess horse to reach a target on a 10×9 grid, accounting for the leg-blocking movement restriction and obstacle squares.

    Model answerBFSgraph traversalboard gamesshortest path
  • Tests Kahn's algorithm with a min-heap to produce the lexicographically smallest valid processing order across nodes in a directed dependency graph, or detect a cycle.

    Auto-gradedtopological-sortgraphsheap
  • Tests backtracking DFS with trie-based pruning to find all words from a large list that can be traced through edge-adjacent, non-repeating cells in a 2-D letter grid.

    Auto-gradedbacktrackingtriedfs
  • Tests understanding of topological sorting, dependency graph modeling, and cycle detection in directed acyclic graphs.

    Auto-gradedtopological-sortgraphsbfscycle-detection
  • Write a recursive function that traverses a binary tree to locate the largest integer value, accounting for null pointers and negative-only trees.

    Model answerrecursionbinary-treetraversaledge-cases
  • Tests BFS/DFS grid traversal by spreading a new color through all 4-directionally connected cells sharing the starting cell's original color.

    Auto-gradedbfsgridgraph-traversal
  • Tests context hashing, union-find for transitive closure, and precise output formatting to group words that are mutually substitutable in identical four-word windows.

    Auto-gradedunion-findhashingstrings

More topics