graph
graph is one of the most repeated interview dimensions. Start with edge-safe fundamentals, then move into pattern-level trade-offs.
Interview Signal
Frequently tests problem modeling, edge handling, and verbal clarity.
Common Pitfall
Template-only answers break under follow-up questioning.
Practice Strategy
Practice in 3-5 problem rounds and always review complexity alternatives.
Recommended Progression
Pattern Bridge
High-Pressure Round
Clone Graph
Clone Graph involves cloning a graph using DFS, focusing on graph traversal and neighbor management using hash tables.
Course Schedule
Determine if all courses can be completed by analyzing prerequisite dependencies using indegree tracking and topological…
Course Schedule II
Solve the 'Course Schedule II' problem using graph indegree and topological ordering, utilizing DFS or BFS to find the c…
Minimum Height Trees
Identify all roots of a tree that produce minimum height using graph indegree analysis and topological trimming.
Longest Increasing Path in a Matrix
Find the length of the longest increasing path in a matrix with given movement constraints using graph techniques.
Reconstruct Itinerary
Reconstruct Itinerary requires building a valid travel route using all tickets once, starting from JFK with lexical orde…
Evaluate Division
Compute the results of division queries from given equations using graph traversal and depth-first search efficiently.
Number of Provinces
Solve Number of Provinces by scanning the adjacency matrix and launching DFS once per unvisited city component.
Redundant Connection
Identify and remove the redundant edge that causes a cycle in a graph starting as a tree.
Redundant Connection II
Find and remove the redundant connection in a directed graph that was originally a rooted tree.
Network Delay Time
Find the minimum time for a signal to travel to all nodes in a directed graph or determine if it's impossible.
Cracking the Safe
The Cracking the Safe problem involves finding the shortest password sequence to unlock a safe using graph traversal and…
Couples Holding Hands
This problem requires arranging couples sitting apart in a row with the minimum number of swaps using graph traversal an…
Is Graph Bipartite?
Determine whether an undirected graph can be split into two independent sets using DFS, BFS, or Union Find patterns.
Cheapest Flights Within K Stops
Find the cheapest flight from a source to a destination with at most K stops using graph traversal techniques efficientl…
All Paths From Source to Target
Find all paths in a directed acyclic graph (DAG) from source to target using depth-first search and backtracking.
Find Eventual Safe States
Solve the problem of finding eventual safe states in a directed graph using depth-first search and topological sorting.
Sum of Distances in Tree
The problem asks to compute the sum of distances between each node and all others in a tree structure using depth-first …
Keys and Rooms
Determine if all rooms can be visited given keys distributed across a set of interconnected locked rooms using graph tra…
Shortest Path Visiting All Nodes
Solve the Shortest Path Visiting All Nodes problem by exploring dynamic programming, bit manipulation, and breadth-first…
Loud and Rich
Determine the quietest person richer than each individual using graph indegree analysis and topological ordering techniq…
Reachable Nodes In Subdivided Graph
The Reachable Nodes In Subdivided Graph problem requires efficiently finding the reachable nodes using graph traversal a…
Possible Bipartition
Determine if a group of n people with mutual dislikes can be split into two non-conflicting groups using graph traversal…
Cat and Mouse
Determine the outcome of a two-player Cat and Mouse game on a graph using topological ordering and memoized dynamic prog…
Minimize Malware Spread
Identify which single infected node to remove to minimize total malware spread in a connected network graph efficiently.
Minimize Malware Spread II
Minimize Malware Spread II asks to minimize the spread of malware in a network of nodes by removing one infected node.
Most Stones Removed with Same Row or Column
Maximize the number of stones removed from a 2D plane using graph traversal and DFS.
Satisfiability of Equality Equations
Determine if it's possible to assign values to variables such that all equations are satisfied based on equality and ine…
Find the Town Judge
Find the Town Judge is an easy LeetCode problem that challenges you to identify a town judge from trust relationships us…
Flower Planting With No Adjacent
In this problem, you are tasked with planting flowers in gardens with specific constraints based on graph traversal prin…
Shortest Path with Alternating Colors
Solve the shortest path problem with alternating edge colors using graph traversal and BFS.
Critical Connections in a Network
Find critical connections in a network of servers, ensuring efficient traversal using depth-first search and Tarjan's al…
Sort Items by Groups Respecting Dependencies
Sort items into groups while respecting dependencies using graph indegree tracking and topological ordering patterns eff…
Maximum Candies You Can Get from Boxes
Collect maximum candies from boxes by exploring initially available boxes and using keys to unlock additional ones effic…
Get Watched Videos by Your Friends
Find videos watched by friends up to a given level and return them sorted by frequency and alphabetically.
Number of Operations to Make Network Connected
Determine the minimum number of operations required to connect all computers in a network with a limited number of cable…
Find the City With the Smallest Number of Neighbors at a Threshold Distance
Find the city with the fewest neighbors within a given threshold distance using dynamic programming.
Validate Binary Tree Nodes
Validate Binary Tree Nodes problem requires checking if a set of nodes forms a valid binary tree using graph traversal.
Minimum Cost to Make at Least One Valid Path in a Grid
Determine the minimum cost to create at least one valid path from the top-left to bottom-right in a directional grid.
Frog Position After T Seconds
The problem asks for the probability that a frog reaches a target vertex after t seconds in a tree graph.
Course Schedule IV
Determine if one course is a prerequisite of another using graph indegree tracking and topological ordering efficiently.
Reorder Routes to Make All Paths Lead to the City Zero
Reorder Routes to Make All Paths Lead to the City Zero involves reversing the direction of roads in a tree to ensure all…
Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree
Identify critical and pseudo-critical edges in a weighted graph's minimum spanning tree using Union Find efficiently.
Parallel Courses II
Determine the minimum semesters to complete all courses with prerequisites using state transition dynamic programming an…
Path with Maximum Probability
Find the path with the highest success probability in a graph from a start node to an end node, using edge probabilities…
Minimum Number of Vertices to Reach All Nodes
Identify the minimum set of vertices in a directed acyclic graph from which all nodes are reachable efficiently using gr…
Remove Max Number of Edges to Keep Graph Fully Traversable
Maximize the number of edges that can be removed while keeping the graph fully traversable for both Alice and Bob.
Min Cost to Connect All Points
Min Cost to Connect All Points asks for the minimum cost to connect all points on a 2D plane, using manhattan distances …
Strange Printer II
Solve Strange Printer II by building color dependencies from bounding rectangles and checking whether a topological orde…
Maximal Network Rank
Calculate the maximum network rank of two cities by analyzing all city pairs using a graph-driven solution strategy effi…
Rank Transform of a Matrix
Compute a unique rank matrix using graph indegree with topological ordering, ensuring each element reflects its relative…
Checking Existence of Edge Length Limited Paths
Solve the problem of checking if there exists a path between two nodes under edge length constraints using efficient tec…
Number Of Ways To Reconstruct A Tree
Determine how many distinct rooted trees can be reconstructed from given node pairs using careful traversal and state tr…
Cat and Mouse II
Cat and Mouse II requires determining if the mouse can reach food before being caught using graph and topological orderi…
Minimum Degree of a Connected Trio in a Graph
Find the minimum degree of a connected trio in a graph using enumeration over nodes and edges.
Count Pairs Of Nodes
Given a graph with nodes and edges, count pairs of nodes where the degree sum exceeds a given threshold for each query.
Number of Restricted Paths From First to Last Node
Solve the problem of finding the number of restricted paths in a weighted undirected graph, leveraging graph algorithms …
Find Center of Star Graph
Find the center node of a star graph, where one node connects to all others.
Largest Color Value in a Directed Graph
Compute the maximum color frequency along any valid path in a directed graph using topological ordering and dynamic prog…
Count Ways to Build Rooms in an Ant Colony
Solve the problem of counting distinct ways to build rooms in an ant colony using dynamic programming and topological or…
Minimum Cost to Reach Destination in Time
Minimize the travel cost in a graph while adhering to a time constraint using state transition dynamic programming.
Find if Path Exists in Graph
Determine if a valid path exists between two vertices in a bi-directional graph using traversal techniques.
Number of Ways to Arrive at Destination
Find the number of ways to travel from intersection 0 to n - 1 in the shortest time, using a graph-based approach.
The Time When the Network Becomes Idle
Calculate the time when the network becomes idle, factoring in message resending and the BFS traversal method.
Second Minimum Time to Reach Destination
Find the second minimum time to reach a destination using BFS while accounting for traffic signal delays in a graph trav…
Parallel Courses III
Solve Parallel Courses III by finding the minimum number of months to complete all courses using graph-based topological…
Maximum Path Quality of a Graph
Calculate the maximum path quality in a graph using backtracking and pruning to optimize node visits within time limits …
Process Restricted Friend Requests
Determine which friend requests can be accepted without violating direct or indirect restrictions using union-find logic…
Find All People With Secret
Find all people who receive a secret through meetings using graph traversal with depth-first search efficiently and corr…
Valid Arrangement of Pairs
Given pairs of numbers, find a valid arrangement where each pair follows a specific condition.
Detonate the Maximum Bombs
Determine the maximum number of bombs that can be detonated by leveraging chain reactions using graph traversal and DFS …
Find All Possible Recipes from Given Supplies
Determine all recipes you can prepare given initial supplies and ingredient dependencies, leveraging array scanning and …
Maximum Employees to Be Invited to a Meeting
Determine the maximum employees to invite based on favorite adjacency constraints using graph indegree and topological o…
All Ancestors of a Node in a Directed Acyclic Graph
Solve the All Ancestors of a Node in a Directed Acyclic Graph problem using graph traversal techniques like BFS, DFS, an…
Minimum Weighted Subgraph With the Required Paths
Find the minimum weighted subgraph that connects three specified nodes in a directed graph with constraints.
Maximum Score of a Node Sequence
Find the maximum score of a valid node sequence in an undirected graph with given node scores and edges.
Longest Path With Different Adjacent Characters
Find the longest path in a tree where adjacent nodes have different characters using graph DFS and topological reasoning…
Maximum Total Importance of Roads
Assign unique values to cities to maximize the total importance of all roads using greedy selection based on city connec…
Minimum Obstacle Removal to Reach Corner
Find the minimum obstacles to remove in a 2D grid to reach the bottom-right corner using BFS graph traversal techniques.
Count Unreachable Pairs of Nodes in an Undirected Graph
Calculate the total number of node pairs in an undirected graph that cannot reach each other using DFS, BFS, or Union Fi…
Number of Increasing Paths in a Grid
Solve Number of Increasing Paths in a Grid by turning cell comparisons into a DAG and counting paths with topological DP…
Find Closest Node to Given Two Nodes
Find the node that minimizes the maximum distance to two given nodes in a directed graph with one outgoing edge per node…
Longest Cycle in a Graph
The problem asks to find the longest cycle in a directed graph with specific edge constraints.
Reachable Nodes With Restrictions
In the 'Reachable Nodes With Restrictions' problem, find the maximum reachable nodes from node 0 in a tree while avoidin…
Node With Highest Edge Score
Determine the node with the highest edge score in a graph using hash table aggregation and careful index tracking.
Build a Matrix With Conditions
Solve the matrix-building problem by using graph indegree and topological sorting to satisfy given row and column constr…
Number of Good Paths
Count all good paths in a tree by scanning node values and using hash maps to track valid connections efficiently.
Most Profitable Path in a Tree
Solve the 'Most Profitable Path in a Tree' problem using graph traversal and depth-first search techniques to maximize A…
Minimum Fuel Cost to Report to the Capital
Calculate the minimum fuel needed for all city representatives to reach the capital using DFS on a tree graph efficientl…
Minimum Score of a Path Between Two Cities
Find the minimum distance in a path connecting two cities using graph traversal strategies efficiently.
Divide Nodes Into the Maximum Number of Groups
Determine the maximum number of groups nodes can form in a graph using depth-first traversal without violating edge conn…
Maximum Star Sum of a Graph
Find the maximum star sum in a graph with specific node values and edges, using greedy algorithms to select the optimal …
Add Edges to Make Degrees of All Nodes Even
Determine if it's possible to add at most two edges to make all node degrees even in an undirected graph.
Minimum Time to Visit a Cell In a Grid
Compute the fastest path in a grid where each cell has a minimum time requirement using BFS and priority queue technique…
Collect Coins in a Tree
The "Collect Coins in a Tree" problem requires traversing a tree to collect coins in the fewest steps while returning to…
Shortest Cycle in a Graph
Find the shortest cycle in a bi-directional graph using BFS for optimal traversal.
Design Graph With Shortest Path Calculator
Implement a dynamic weighted directed graph with efficient shortest path queries and edge additions in real time.
Minimize the Total Price of the Trips
Calculate the minimum total cost of multiple trips on a tree by selectively halving node prices using DFS frequency coun…
Minimum Cost of a Path With Special Roads
Find the minimum cost path between two points, using special roads or direct moves in a 2D space.
Count the Number of Complete Components
Determine the number of complete connected components in an undirected graph using efficient traversal techniques and gr…
Modify Graph Edge Weights
Modify Graph Edge Weights is a graph problem where you adjust edge weights to match a target shortest path distance.
Minimum Edge Weight Equilibrium Queries in a Tree
Find the minimum number of operations to equalize edge weights in a tree between given pairs of nodes.
Minimum Edge Reversals So Every Node Is Reachable
This problem requires solving a graph traversal with edge reversals to ensure every node is reachable in a tree-like str…
Count Visited Nodes in a Directed Graph
Count Visited Nodes in a Directed Graph uses dynamic programming to solve graph traversal and node visitation counting e…
Find Champion II
Identify the strongest team in a tournament DAG using graph-driven logic, ensuring correct handling of in-degree zero ch…
Number of Possible Sets of Closing Branches
Calculate all valid sets of branch closures while keeping remaining branches within maxDistance using bitmask and graph …
Minimum Cost to Convert String I
This problem asks to calculate the minimum cost to convert a string from source to target using specific character trans…
Minimum Cost to Convert String II
Compute the minimum cost to transform source into target using substring replacements with given costs efficiently using…
Count the Number of Houses at a Certain Distance I
Determine the number of house pairs at each street distance using graph traversal and breadth-first search efficiently.
Count the Number of Houses at a Certain Distance II
Count the Number of Houses at a Certain Distance II is a graph problem that requires efficient pair counting with an add…
Minimum Cost Walk in Weighted Graph
Find the minimum cost walk in a weighted graph using array and bit manipulation techniques for efficient path calculatio…
Minimum Time to Visit Disappearing Nodes
Determine the minimum time to visit each node in a disappearing-node graph using arrays, graphs, and priority queues eff…
Find Edges in Shortest Paths
Use two Dijkstra runs to mark exactly which edges can appear on at least one shortest path from 0 to n - 1.
Find Minimum Diameter After Merging Two Trees
Calculate the minimum diameter after merging two trees by strategically connecting nodes to minimize the longest path in…
Time Taken to Mark All Nodes
Calculate the time taken to mark all nodes in a tree, starting from any node with time t=0.
Shortest Distance After Road Addition Queries I
Solve shortest paths dynamically in a growing graph using BFS, updating distances efficiently after each road addition q…
Shortest Distance After Road Addition Queries II
The problem involves calculating the shortest path from city 0 to city n-1 after each road addition, leveraging greedy c…
Find a Safe Walk Through a Grid
Determine if you can safely traverse a binary grid from top-left to bottom-right using limited health points.
Remove Methods From Project
Remove suspicious methods in a project that are invoked directly or indirectly from a buggy method using graph traversal…
Construct 2D Grid Matching Graph Layout
This problem challenges you to construct a 2D grid from an undirected graph using a given set of edges.
Find Minimum Time to Reach Last Room I
Find Minimum Time to Reach Last Room I challenges you to determine the minimum time to travel in a dungeon with a grid l…
Find Minimum Time to Reach Last Room II
Calculate the minimum time to reach the last room in a grid with alternating move times using array and graph patterns.
Digit Operations to Make Two Integers Equal
Transform n into m using allowed digit operations without creating primes, applying math and graph strategies efficientl…
Maximize Amount After Two Days of Conversions
Compute the maximum currency amount after two days using graph traversal and depth-first search for optimal conversions.
Minimize the Maximum Edge Weight of Graph
Minimize the maximum edge weight in a graph after removing certain edges while ensuring node reachability.
Frequencies of Shortest Supersequences
Compute all unique shortest common supersequences of given words using graph indegree tracking and topological ordering …
Properties Graph
Find the number of connected components in an undirected graph formed by properties arrays, using array scanning and has…
Unit Conversion I
Solve the unit conversion problem by using graph traversal to compute equivalent unit amounts.
Maximum Profit from Valid Topological Order in DAG
Solve the Maximum Profit from Valid Topological Order in DAG problem using graph indegree and topological sorting with d…
Path Existence Queries in a Graph I
Determine if paths exist between nodes using array scanning and hash lookups for efficient component checks in graphs.
Path Existence Queries in a Graph II
Solve path existence queries in a graph using binary search on the answer space, focusing on sorted nodes and maximum di…
Maximum Weighted K-Edge Path
Determine the maximum sum of edge weights for a k-edge path in a DAG using state transition dynamic programming efficien…
Maximum Sum of Edge Values in a Graph
Maximize the sum of edge values in a connected graph by assigning unique node values and optimizing edge products.
Minimum Time to Transport All Individuals
Find the minimum time to transport individuals across a river with dynamic environmental conditions and boat capacity.
Maximize Spanning Tree Stability with Upgrades
Maximizing the stability of a spanning tree with upgrades requires careful optimization of edge strengths using binary s…
Minimum Time to Reach Destination in Directed Graph
The problem involves finding the minimum time to reach the destination in a directed graph with time-dependent edges.
Power Grid Maintenance
Determine which power stations remain connected after maintenance using array scanning and hash lookups to track compone…
Minimum Time for K Connected Components
Find the minimum time to remove edges such that a graph with n nodes has at least k connected components.
Minimize Maximum Component Cost
Minimize Maximum Component Cost leverages binary search over edge weights to optimize the cost of graph components after…
Longest Palindromic Path in Graph
Find the longest path in a graph that forms a palindrome using state transition dynamic programming and bitmask techniqu…
Network Recovery Pathways
Find the maximum recovery cost of valid paths in a directed acyclic graph where some nodes are offline.
Related Patterns
Graph traversal with depth-first search
43 linked problems
Graph indegree plus topological ordering
22 linked problems
Graph-driven solution strategy
13 linked problems
Array scanning plus hash lookup
12 linked problems
Graph indegree plus topological ordering
11 linked problems
Graph plus Heap (Priority Queue)
11 linked problems