KatInterview

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

Trees & Graphs Interview Problems

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

5967
Problems
2210
Auto-graded
15
Topics
272
Added today

Showing 1–30 of 85 results

  • Trees & GraphsHardModel answer
    Construct Non-Conflicting Queens Configurations

    Compute all possible configurations of n non-attacking queens on an n x n board using stateful depth-first search.

    Trees & Graphsbacktrackingrecursiondepth-first-search
  • Trees & GraphsHardModel answer
    Grid Partitioning and Navigating Safe Subregions

    Construct a valid contiguous layout for multiple crop zones on a grid and find the shortest path avoiding edge-touching zones.

    Trees & Graphstrees-graphsgridbfsconstructive-algorithms
  • Trees & GraphsMediumModel answer
    Graph Toolkit for Scene and Dependency Graphs: Sort, Traverse, Route

    Implement topological sort, BFS, DFS and Dijkstra on a dependency graph, then discuss CSR versus adjacency lists, CPU/GPU parallel traversal, and deterministic testing.

    Trees & Graphstopological-sortbfs-dfsdijkstracsr
  • Trees & GraphsEasyModel answer
    Count Activations per Node in a Cascade Graph

    Given a DAG of task dependencies and one start node, compute how many times each node fires when every activation fans out once along every outgoing edge.

    Trees & Graphsdagtopological-sortpath-countinggraph-traversal
  • Trees & GraphsMediumModel answer
    Reconstruct Binary Tree from Inorder and Postorder Sequences

    Reconstruct a binary tree given its inorder and postorder traversal arrays, assuming all node values are unique.

    Trees & Graphstrees-graphsrecursionhash-table
  • Trees & GraphsMediumModel answer
    Identify Node Value Present Across Most Depth Levels

    Find the binary tree node value that appears across the highest number of unique depth levels.

    Trees & Graphstrees-graphsbreadth-first-searchhash-table
  • Trees & GraphsHardModel answer
    Region-Splitting Tree and Multi-Word Grid Search

    Compress a square character grid into a four-way region tree, then locate a batch of words in the grid by walking neighbors in eight directions without reusing cells.

    Trees & Graphsquadtreetriebacktrackingdivide-and-conquer
  • Trees & GraphsMediumModel answer
    Mapping a Hidden Maze: Shortest Route for a Sensing Robot

    A robot in an unseen grid senses neighbours for free and pays per move. Find a shortest route to a target, or return to the start and report failure if none exists.

    Trees & Graphsbfsgridonline-explorationshortest-path
  • Trees & GraphsMediumModel answer
    Right Edge of a Tree and Minimal Bracket Removal

    Two linked tasks: list the nodes visible from the right of a binary tree, and delete the fewest parentheses from a string so the rest is balanced.

    Trees & Graphsbinary-treebfsstackstrings
  • Trees & GraphsMediumModel answer
    Friend Product Suggestions and Click-Path Reachability

    Two short coding tasks: suggest products that a user's friends bought but the user hasn't, and decide whether one URL can reach another through recorded navigation steps.

    Trees & Graphshash-setset-differencegraphbfs
  • Trees & GraphsMediumModel answer
    Resolve Variables from Linked Assignment Rules with Cycle Checks

    Evaluate a target variable from a list of assignment strings, growing from simple aliasing to signed sums of variables and integers, then detect circular dependencies safely.

    Trees & Graphsparsingmemoizationdfscycle-detection
  • Trees & GraphsEasyModel answer
    Binary Tree Lateral Perspective and Zero-Sum Triplet Extraction

    Solve two fundamental interview tasks: identifying the rightmost nodes of a binary tree by level and finding non-duplicate zero-sum triplets in an un-ordered array.

    Trees & Graphsbinary-treebfstwo-pointerssorting
  • Trees & GraphsMediumModel answer
    Robot Navigation on a Hidden Grid with DFS and Backtracking

    Guide a robot through a map it can only discover step by step, reaching the target with no repeated visits, real backtracking, and a clear result when the target is unreachable.

    Trees & Graphsdfsbacktrackinggraph-traversalgrid
  • Trees & GraphsMediumModel answer
    Sliding Block Minimums and Dependency-Ordered Cooking Plan

    Compute the minimum of every K x K window in a grid, then order recipes so that every derived ingredient is made before the dish that uses it, detecting cycles.

    Trees & Graphstopological-sortmonotonic-dequesliding-windowkahns-algorithm
  • Trees & GraphsMediumModel answer
    Find a Money-Making Loop in a Table of Exchange Rates

    Given directed currency exchange quotes, decide whether some round trip returns more than it started with, and output one such round trip as an ordered list of currencies.

    Trees & Graphsgraphbellman-fordnegative-cyclefloating-point
  • Trees & GraphsHardModel answer
    Shortest Hop Count Through a Flaky Web Graph

    Crawl a website graph from a start URL to an exit page using BFS, retrying transient 5xx failures a limited number of times, and return the minimum hop count or -1.

    Trees & Graphsbfsgraph-traversalretry-logicvisited-set
  • Trees & GraphsMediumModel answer
    Two Warm-Ups: One-Deletion Palindrome and Column-Grouped Tree Output

    Decide whether a string becomes a palindrome after removing at most one character, then group a binary tree's node values by column using level-order tie-breaking.

    Trees & Graphstwo-pointerspalindromebfsbinary-tree
  • Trees & GraphsMediumModel answer
    Unify Contact Profiles Linked by Common Email Addresses

    Combine contact records that are directly or transitively linked by a shared email, outputting each person's name with a deduplicated, sorted email list.

    Trees & Graphsunion-findgraphconnected-componentsdfs
  • Trees & GraphsHardModel answer
    Fastest Route Through Only the Courses a Goal List Needs

    Given courses with durations, prerequisite links and a list of goal courses, compute the minimum time to finish the goals and their needed prerequisites, as total effort and as elapsed time.

    Trees & Graphsgraphtopological-sortdagcycle-detection
  • Trees & GraphsMediumModel answer
    Build a Display Order for Tasks with Dedup, Filtering and Subtasks

    Turn a flat batch of scheduler tasks into a display list: merge duplicates, hide finished work, order by priority, and keep each subtask right under its parent.

    Trees & Graphssortinghashingtree-traversalcycle-detection
  • Trees & GraphsMediumModel answer
    Distributed Tree Traversal and Reliable Neighbor Messaging Protocol

    Design a reliable message passing protocol across adjacent tree nodes, then compute total network size and discover paths under network faults.

    Trees & Graphstrees-graphsdistributed-systemsmessage-passingnetwork-protocol
  • Trees & GraphsMediumModel answer
    Modeling Classic Puzzles: River Crossing, Jugs, and Proofs

    Turn a set of contest-style logic puzzles, led by the fox-chicken-grain river crossing, into formal models, and give algorithms with proofs of correctness and optimality.

    Trees & Graphsbfsstate-space-searchinvariantsproofs
  • Trees & GraphsMediumModel answer
    Feature Flag Rollout Validator with Dependency Cycle Detection

    Parse feature dependency specs, run modular checksum verification, and evaluate user eligibility and feature graph dependencies while handling cyclic rollouts.

    Trees & Graphstrees-graphsstringsdepth-first-search
  • Trees & GraphsHardModel answer
    Topological Task Scheduler and Strict Expression Parser

    Solve a task dependency ordering problem via topological sort and build an expression evaluator supporting custom operator precedence, unary signs, and overflow checks.

    Trees & Graphstopological-sortgraph-algorithmsexpression-parserstacks
  • Trees & GraphsHardModel answer
    Evaluate Chained Sum Definitions with Error Detection

    Compute the integer value of every variable defined as a sum of literals and other variables, raising distinct errors for duplicate, undefined, or circular definitions.

    Trees & Graphstopological-sortgraphkahn-algorithmcycle-detection
  • Trees & GraphsMediumModel answer
    Repairing a Search Tree After One Pair of Keys Trades Places

    Two keys in a binary search tree were exchanged by mistake. Restore ordering by swapping values back, keeping the shape intact, in linear time and constant extra space.

    Trees & Graphsbinary-search-treemorris-traversalin-ordertree-recovery
  • Trees & GraphsMediumModel answer
    Minimum Additions to Equalize Every Subtree Sum

    Calculate the minimum non-negative value additions needed so that the node sum of every subtree in a binary tree equals K, returning -1 if impossible.

    Trees & Graphstrees-graphspost-ordergreedydepth-first-search
  • Trees & GraphsMediumModel answer
    Same-Host Link Crawler: Sequential and Concurrent Versions

    Crawl every page reachable from a seed URL on the same host, ignoring URL fragments, first with one thread and then with a thread-safe parallel design.

    Trees & Graphsbfsgraph-traversalconcurrencythread-pool
  • Trees & GraphsMediumModel answer
    Build a Collapsible JSON Tree Renderer in React

    Design and implement a React component to display nested JSON with collapsible nodes, indentation, and syntax highlighting for primitive types.

    Trees & GraphsReactJSONTreeFrontend
  • Trees & GraphsMediumModel answer
    Analyze Referral Chains and Detect Graph Cycles

    Process 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.

    Trees & Graphstrees-graphsdfscycle-detectiongraph-traversal