KatInterview

practice a little every day — you've got this ♡

Trees & Graphs Interview Problems

Practice 5980 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.

5980
Problems
2215
Auto-graded
15
Topics
272
Added today

Showing 211–240 of 434 results

  • Trees & GraphsHardModel answer
    Principal Types for a Tiny Lambda Calculus

    Build an AST for variables, lambdas and applications, then infer each expression's most general function type using unification, with an occurs check to reject infinite types.

    Trees & Graphstype-inferenceunificationhindley-milnerast
  • Trees & GraphsEasyAuto-graded
    Reporting Chain Length Between Two Employees

    Find the number of links on the path between two people in a company tree given as pairs, which tests undirected graph modeling and BFS or lowest common ancestor reasoning.

    Trees & Graphsgraphbfstreeshortest-path
  • Trees & GraphsMediumModel answer
    Tallying a Tree of Message-Passing Processes

    Each tree node is an isolated process with only async send and blocking receive. Design a protocol so the root learns the tree size, tolerates lost and duplicate messages, and returns a structured result.

    Trees & Graphsdistributed-systemsconvergecastidempotencyretries
  • Trees & GraphsMediumAuto-graded
    Words Traced Through a Letter Board

    Find every dictionary word that can be traced through orthogonally adjacent cells of a letter board without reusing a cell, using backtracking guided by a prefix tree.

    Trees & Graphsbacktrackingtriedfsgrid
  • Trees & GraphsMediumAuto-graded
    Nearest Exit Distance Map on a Walled Grid

    Compute, for every open cell of a grid with walls and exits, the shortest 4-directional distance to any exit using multi-source BFS, leaving unreachable cells unchanged.

    Trees & Graphsbfsgridmulti-source-bfsmatrix
  • Trees & GraphsMediumAuto-graded
    Service Inventory Filter and Dependency Risk Report

    Filter a service inventory by namespace, attributes and status, then compute transitive dependencies and risk flags from a root service, handling cycles and dangling references.

    Trees & Graphsgraph-traversaldfshash-mapfiltering
  • Trees & GraphsMediumAuto-graded
    Shortest Route to an Exit with Fixed Direction Priority

    Run BFS on a character grid to return the shortest move sequence to any exit, breaking ties by a fixed U, D, L, R direction priority.

    Trees & Graphsbfsgridshortest-pathpath-reconstruction
  • Trees & GraphsMediumAuto-graded
    Best Island Total with Row-Major Boundary Cells

    Find connected components in a signed grid and pick the best-scoring one, with and without a no-negatives rule, reporting its first and last row-major cells.

    Trees & Graphsgriddfsconnected-componentstie-breaking
  • Trees & GraphsMediumAuto-graded
    Costliest Root Task in a Task Forest

    Sum durations over each root's subtree in a parent-linked record list and return the root with the largest total, testing tree aggregation and iterative traversal.

    Trees & Graphstreedfshash-mapiterative-traversal
  • Trees & GraphsMediumAuto-graded
    Best Conversion Product Over Simple Currency Paths

    Find the largest product of edge weights over simple directed paths between two nodes, using backtracking DFS, with a special case for identical endpoints and an unreachable case.

    Trees & Graphsgraphdfsbacktrackingsimple-paths
  • Trees & GraphsMediumAuto-graded
    Net Access Letters Across a Dependency Hierarchy

    Compute each node's final letter set in a DAG where grants flow to all descendants but revocations apply only to the node that declares them.

    Trees & Graphsgraphdagtopological-sortbitmask
  • Trees & GraphsMediumAuto-graded
    Batch Ratio Lookup Over Linked Quantities

    Answer many ratio queries between named quantities from pairwise ratio facts, using a weighted union-find or component precomputation instead of a search per query.

    Trees & Graphsunion-findgraphweighted-union-findbatch-queries
  • Trees & GraphsMediumAuto-graded
    Largest Chain Reaction From a Single Detonation

    Model one-way blast reach as a directed graph and find the largest set reachable from any single starting node, using exact integer distance checks.

    Trees & Graphsgraphdfsreachabilitygeometry
  • Trees & GraphsMediumAuto-graded
    Find the Exit of a Keyed Forest Graph

    Run a breadth-first search over (location, keys held) states in a forest with locked doors to find the first exit reached, or None.

    Trees & Graphsbfsgraphstate-space-searchparsing
  • Trees & GraphsMediumAuto-graded
    Column Grid from a Tree: Reach a Value by Walking Non-Zero Cells

    Project a heap-indexed binary tree onto a depth-by-column grid, then use BFS over non-zero cells to decide whether a cell holding the target is reachable from a given start.

    Trees & Graphsbinary-treebfsgridvertical-order
  • Trees & GraphsMediumAuto-graded
    Eager Formula Sheet with Cycle-Safe Updates

    Simulate a mini spreadsheet where formulas are evaluated at write time, dependents update eagerly, and any write that would create a dependency cycle is rejected without changing state.

    Trees & Graphsdependency graphtopological sortcycle detectionsimulation
  • Trees & GraphsMediumAuto-graded
    Duplicate a Nested Structure With Cycles and Shared Parts

    Build an independent deep copy of a nested container structure, preserving shared references and cycles, using a memo table and an explicit stack.

    Trees & Graphsdeep-copygraph-traversalmemoizationiterative-dfs
  • Trees & GraphsMediumModel answer
    Crawl a Web-Served Labyrinth Through Unreliable Responses

    Write a crawler that explores a maze of HTTP endpoints to find the exit, coping with cycles, transient 503 errors and malformed JSON, while guaranteeing termination.

    Trees & Graphsgraph-traversalbfshttpretries
  • Trees & GraphsMediumAuto-graded
    Uncover Cells on a Minefield Grid with Flood Expansion

    Apply a Minesweeper-style tap to a grid, expanding through zero-mine regions with breadth-first search and labeling cells with adjacent mine counts.

    Trees & Graphsbfsgridmatrixsimulation
  • Trees & GraphsMediumAuto-graded
    Grid Distance to the Closest Marked Cell

    Compute, for every cell of a grid, the fewest orthogonal steps to the closest marked cell, using a single multi-source breadth-first search; -1 everywhere when no cell is marked.

    Trees & Graphsbfsmulti-source-bfsgridshortest-path
  • Trees & GraphsMediumAuto-graded
    Chained Exchange Rates: Resolve Conversion Queries

    Build a bidirectional weighted graph from exchange rates and answer conversion queries with a deterministic BFS that multiplies rates along the first-found path, or -1.0 if none exists.

    Trees & Graphsgraphbfsweighted-graphhash-map
  • Trees & GraphsMediumAuto-graded
    Is the Target's Cell Forced by Every Valid Seating?

    Backtracking over placements of named items on a grid under pairwise relative-position clues, deciding whether the target ends up in one cell across all valid layouts.

    Trees & Graphsbacktrackingconstraint-satisfactiongridsearch
  • Trees & GraphsHardAuto-graded
    Semester Planner Plus Burst-Limited Request Filter

    Combine topological ordering to find the minimum number of semesters (or detect a cycle) with a deque-based simulation of a two-rule request throttle that reports dropped timestamps.

    Trees & Graphstopological-sortgraphcycle-detectionsliding-window
  • Trees & GraphsMediumModel answer
    Concurrent Site Crawler with Fault-Tolerant Fetching

    Build a crawler that explores every page reachable from a seed URL using a slow, flaky link API, evolving from a sequential traversal to a thread pool with bounded, backoff-driven retries.

    Trees & Graphsweb-crawlerconcurrencybfsretries
  • Trees & GraphsMediumAuto-graded
    Live Archipelago Counter with Incremental Land Reclamation

    Count 4-connected land regions in a grid, then report the updated region count after each cell is converted from water to land, using incremental connectivity.

    Trees & Graphsunion-findgridconnected-componentsincremental-updates
  • Trees & GraphsMediumModel answer
    Crawl One Site: Sequential Traversal, Then a Parallel Version

    Collect every page reachable from a seed URL on the same host, ignoring URL fragments and fetching each page once, first with one thread and then with safe concurrency.

    Trees & Graphsweb-crawlerbfsconcurrencythread-safety
  • Trees & GraphsMediumModel answer
    Print a Reporting Hierarchy and List Two-Level-Down Pairs

    Turn manager rows into a tree, infer the root, print it with depth-based dot indentation, or list every (manager, employee) pair exactly two levels apart.

    Trees & Graphstreepreorderiterative-dfshash-map
  • Trees & GraphsMediumAuto-graded
    Cheapest Letter Rewrites with Directed Price Rules

    Compute the minimum cost to rewrite one string into another with directed priced letter swaps, using shortest paths over 26 letters and handling impossible positions and large totals.

    Trees & Graphsgraphfloyd-warshallshortest-pathstrings
  • Trees & GraphsMediumAuto-graded
    Fewest-Hop Route Through Flaky Page Fetches

    Run BFS on a link graph to find the lexicographically smallest fewest-hop route, where some pages fail a set number of times before their links load.

    Trees & Graphsbfsgraphshortest-pathretries
  • Trees & GraphsMediumAuto-graded
    Rainbow Walks of Length Three in a Typed Graph

    Count ordered 4-vertex walks along edges in an undirected graph whose vertices carry one of four labels, where each walk uses every label exactly once.

    Trees & Graphsgraphcountingcombinatoricsadjacency-list