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 391–420 of 434 results

  • Tests understanding of constrained shortest-path algorithms on directed weighted graphs with edge-count restrictions.

    Auto-gradedgraphsshortest-pathbellman-fordconstraints
  • Tests BFS on an implicit graph with efficient neighbor generation using wildcard pattern indexing.

    Auto-gradedbfsgraphstringhashing
  • Tests understanding of single-source shortest path algorithms on weighted directed graphs with positive edge weights.

    Auto-gradedshortest-pathdijkstragraph-traversalpriority-queue
  • Tests graph traversal for connected components in a binary grid and combinatorial counting with multiset constraints.

    Auto-gradedgraph-traversalbfsconnected-componentscombinatorics
  • Tests tree DP by computing the maximum total weight of a node subset where no two chosen nodes share an edge (weighted tree independent set).

    Auto-gradedtreesdynamic programminggraph traversal
  • Build a mini spreadsheet engine that evaluates formulas, detects circular dependencies, and handles dynamic updates.

    Auto-gradedgraphsdfsrecursionmemoization
  • Tests graph traversal skills by identifying connected components in a 2D grid using BFS or DFS.

    Auto-gradedgraph-traversalbfsdfsconnected-components
  • Measures understanding of graph traversal on a grid to compute connected-component sizes using four-directional adjacency.

    Auto-gradedgraphsdfsconnected-componentsgrid-traversal
  • Tests BFS-based grid simulation with simultaneous state updates, barrier cells, and handling extremely large iteration counts efficiently.

    Auto-gradedbfsgridsimulationqueue
  • Compute each node's height in a rooted tree and group nodes by height, testing tree traversal and bottom-up computation.

    Auto-gradedtreesbfsheightbottom-up
  • Tests breadth-first search from multiple sources to model time-based propagation in a grid with obstacles and unreachable regions.

    Auto-gradedbfsgridmulti-sourcegraph-traversal
  • Tests tree reconstruction and ancestor tracking to locate the closest common parent of two given values in a binary tree.

    Auto-gradedbinary-treetree-traversalancestor-search
  • Implement a recursive game-tree solver that finds the outcome under optimal play and identifies a winning or drawing move for the current player.

    Auto-gradedrecursionbacktrackinggame-theoryminimax
  • Tests graph traversal, parent-pointer navigation, and root identification in tree-like structures represented as parent references.

    Auto-gradedgraphstreeshash-mapspath-finding
  • Tests tree DP (rerooting) by finding the node from which the maximum sum of weighted edges can be collected along any single root-to-leaf path in a tree.

    Auto-gradedtreesdynamic-programmingtree-dpdepth-first-search
  • Tests post-order traversal, heap indexing in complete binary trees, and efficient bottom-up aggregation without recursion.

    Auto-gradedbinary-treespost-order-traversalcomplete-binary-treeaggregation
  • Tests offline dynamic graph connectivity using a segment-tree-over-time with a rollback-capable union-find to handle both edge insertions and deletions.

    Auto-gradedunion-findsegment-treedynamic-connectivity
  • Tests ability to apply topological ordering to determine a valid execution sequence of tasks where each task may unlock resources required by others.

    Auto-gradedgraphstopological sortDAGKahn's algorithm
  • Tests hierarchical graph traversal and efficient permission accumulation using ancestor path lookup and set operations.

    Auto-gradedgraphstreesbfscaching
  • Tests graph traversal and dynamic programming on DAGs to compute propagated weight contributions through dependency chains.

    Auto-gradedgraphsdagtopological-sortdynamic-programming
  • Tests whether a candidate can produce a valid topological ordering of a build-dependency DAG and apply a precise tie-break rule when multiple orderings exist.

    Auto-gradedgraphstopological sortBFSKahn's algorithm
  • Tests the ability to extend Dijkstra's algorithm with a constrained resource (fuel), requiring candidates to track both position and remaining fuel as state.

    Auto-gradedgraphsdijkstrashortest pathdynamic programming
  • Determine the path between two nodes in a Fibonacci-style binary tree using only their preorder indices, without building the tree in memory.

    Model answerbinary-treesrecursionfibonaccitree-traversal
  • Tests union-find (disjoint set union) to group transmission lines into connected components and answer queries about grid connectivity.

    Auto-gradedunion-findgraphsconnected-components
  • Tests multi-source BFS to find the time until a grid-based propagation process completes or determine impossibility.

    Auto-gradedbreadth-first-searchgridmulti-source-bfs
  • Tests graph traversal with edge reversal to find all nodes reachable through reversed dependency edges, handling cycles correctly.

    Auto-gradedgraph-traversalbfsdirected-graphcycle-detection
  • Tests whether a candidate can produce a valid topological ordering of task dependencies while breaking ties by smallest task ID for determinism.

    Auto-gradedgraphstopological sortBFSKahn's algorithm
  • Write a crawler that visits all pages reachable from a start URL, staying within the same domain, avoiding cycles and duplicate fetches.

    Model answergraph-traversalbfsdfsurl-parsing
  • Tests tree DP on a weighted tree to find the maximum sum of node values along any root-to-leaf path, using depth-first traversal and subproblem combination.

    Auto-gradedtreesdynamic programmingdepth-first search
  • Parse Git diffs and a CSV ownership map to identify which contributor owns the most modified files in a branch comparison.

    Model answergitfile-iocsvaggregation

More topics