LeetCodechevron_rightCategorieschevron_rightgraph
hub

graph

141 problems
Easy: 3Medium: 66Hard: 72

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

#TitleDifficulty
133

Clone Graph

Clone Graph involves cloning a graph using DFS, focusing on graph traversal and neighbor management using hash tables.

Medium
207

Course Schedule

Determine if all courses can be completed by analyzing prerequisite dependencies using indegree tracking and topological…

Medium
210

Course Schedule II

Solve the 'Course Schedule II' problem using graph indegree and topological ordering, utilizing DFS or BFS to find the c…

Medium
310

Minimum Height Trees

Identify all roots of a tree that produce minimum height using graph indegree analysis and topological trimming.

Medium
329

Longest Increasing Path in a Matrix

Find the length of the longest increasing path in a matrix with given movement constraints using graph techniques.

Hard
332

Reconstruct Itinerary

Reconstruct Itinerary requires building a valid travel route using all tickets once, starting from JFK with lexical orde…

Hard
399

Evaluate Division

Compute the results of division queries from given equations using graph traversal and depth-first search efficiently.

Medium
547

Number of Provinces

Solve Number of Provinces by scanning the adjacency matrix and launching DFS once per unvisited city component.

Medium
684

Redundant Connection

Identify and remove the redundant edge that causes a cycle in a graph starting as a tree.

Medium
685

Redundant Connection II

Find and remove the redundant connection in a directed graph that was originally a rooted tree.

Hard
743

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.

Medium
753

Cracking the Safe

The Cracking the Safe problem involves finding the shortest password sequence to unlock a safe using graph traversal and…

Hard
765

Couples Holding Hands

This problem requires arranging couples sitting apart in a row with the minimum number of swaps using graph traversal an…

Hard
785

Is Graph Bipartite?

Determine whether an undirected graph can be split into two independent sets using DFS, BFS, or Union Find patterns.

Medium
787

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…

Medium
797

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.

Medium
802

Find Eventual Safe States

Solve the problem of finding eventual safe states in a directed graph using depth-first search and topological sorting.

Medium
834

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 …

Hard
841

Keys and Rooms

Determine if all rooms can be visited given keys distributed across a set of interconnected locked rooms using graph tra…

Medium
847

Shortest Path Visiting All Nodes

Solve the Shortest Path Visiting All Nodes problem by exploring dynamic programming, bit manipulation, and breadth-first…

Hard
851

Loud and Rich

Determine the quietest person richer than each individual using graph indegree analysis and topological ordering techniq…

Medium
882

Reachable Nodes In Subdivided Graph

The Reachable Nodes In Subdivided Graph problem requires efficiently finding the reachable nodes using graph traversal a…

Hard
886

Possible Bipartition

Determine if a group of n people with mutual dislikes can be split into two non-conflicting groups using graph traversal…

Medium
913

Cat and Mouse

Determine the outcome of a two-player Cat and Mouse game on a graph using topological ordering and memoized dynamic prog…

Hard
924

Minimize Malware Spread

Identify which single infected node to remove to minimize total malware spread in a connected network graph efficiently.

Hard
928

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.

Hard
947

Most Stones Removed with Same Row or Column

Maximize the number of stones removed from a 2D plane using graph traversal and DFS.

Medium
990

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…

Medium
997

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…

Easy
1042

Flower Planting With No Adjacent

In this problem, you are tasked with planting flowers in gardens with specific constraints based on graph traversal prin…

Medium
1129

Shortest Path with Alternating Colors

Solve the shortest path problem with alternating edge colors using graph traversal and BFS.

Medium
1192

Critical Connections in a Network

Find critical connections in a network of servers, ensuring efficient traversal using depth-first search and Tarjan's al…

Hard
1203

Sort Items by Groups Respecting Dependencies

Sort items into groups while respecting dependencies using graph indegree tracking and topological ordering patterns eff…

Hard
1298

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…

Hard
1311

Get Watched Videos by Your Friends

Find videos watched by friends up to a given level and return them sorted by frequency and alphabetically.

Medium
1319

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…

Medium
1334

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.

Medium
1361

Validate Binary Tree Nodes

Validate Binary Tree Nodes problem requires checking if a set of nodes forms a valid binary tree using graph traversal.

Medium
1368

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.

Hard
1377

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.

Hard
1462

Course Schedule IV

Determine if one course is a prerequisite of another using graph indegree tracking and topological ordering efficiently.

Medium
1466

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…

Medium
1489

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.

Hard
1494

Parallel Courses II

Determine the minimum semesters to complete all courses with prerequisites using state transition dynamic programming an…

Hard
1514

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…

Medium
1557

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…

Medium
1579

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.

Hard
1584

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 …

Medium
1591

Strange Printer II

Solve Strange Printer II by building color dependencies from bounding rectangles and checking whether a topological orde…

Hard
1615

Maximal Network Rank

Calculate the maximum network rank of two cities by analyzing all city pairs using a graph-driven solution strategy effi…

Medium
1632

Rank Transform of a Matrix

Compute a unique rank matrix using graph indegree with topological ordering, ensuring each element reflects its relative…

Hard
1697

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…

Hard
1719

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…

Hard
1728

Cat and Mouse II

Cat and Mouse II requires determining if the mouse can reach food before being caught using graph and topological orderi…

Hard
1761

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.

Hard
1782

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.

Hard
1786

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 …

Medium
1791

Find Center of Star Graph

Find the center node of a star graph, where one node connects to all others.

Easy
1857

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…

Hard
1916

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…

Hard
1928

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.

Hard
1971

Find if Path Exists in Graph

Determine if a valid path exists between two vertices in a bi-directional graph using traversal techniques.

Easy
1976

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.

Medium
2039

The Time When the Network Becomes Idle

Calculate the time when the network becomes idle, factoring in message resending and the BFS traversal method.

Medium
2045

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…

Hard
2050

Parallel Courses III

Solve Parallel Courses III by finding the minimum number of months to complete all courses using graph-based topological…

Hard
2065

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 …

Hard
2076

Process Restricted Friend Requests

Determine which friend requests can be accepted without violating direct or indirect restrictions using union-find logic…

Hard
2092

Find All People With Secret

Find all people who receive a secret through meetings using graph traversal with depth-first search efficiently and corr…

Hard
2097

Valid Arrangement of Pairs

Given pairs of numbers, find a valid arrangement where each pair follows a specific condition.

Hard
2101

Detonate the Maximum Bombs

Determine the maximum number of bombs that can be detonated by leveraging chain reactions using graph traversal and DFS …

Medium
2115

Find All Possible Recipes from Given Supplies

Determine all recipes you can prepare given initial supplies and ingredient dependencies, leveraging array scanning and …

Medium
2127

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…

Hard
2192

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…

Medium
2203

Minimum Weighted Subgraph With the Required Paths

Find the minimum weighted subgraph that connects three specified nodes in a directed graph with constraints.

Hard
2242

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.

Hard
2246

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…

Hard
2285

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…

Medium
2290

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.

Hard
2316

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…

Medium
2328

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…

Hard
2359

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…

Medium
2360

Longest Cycle in a Graph

The problem asks to find the longest cycle in a directed graph with specific edge constraints.

Hard
2368

Reachable Nodes With Restrictions

In the 'Reachable Nodes With Restrictions' problem, find the maximum reachable nodes from node 0 in a tree while avoidin…

Medium
2374

Node With Highest Edge Score

Determine the node with the highest edge score in a graph using hash table aggregation and careful index tracking.

Medium
2392

Build a Matrix With Conditions

Solve the matrix-building problem by using graph indegree and topological sorting to satisfy given row and column constr…

Hard
2421

Number of Good Paths

Count all good paths in a tree by scanning node values and using hash maps to track valid connections efficiently.

Hard
2467

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…

Medium
2477

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…

Medium
2492

Minimum Score of a Path Between Two Cities

Find the minimum distance in a path connecting two cities using graph traversal strategies efficiently.

Medium
2493

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…

Hard
2497

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 …

Medium
2508

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.

Hard
2577

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…

Hard
2603

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…

Hard
2608

Shortest Cycle in a Graph

Find the shortest cycle in a bi-directional graph using BFS for optimal traversal.

Hard
2642

Design Graph With Shortest Path Calculator

Implement a dynamic weighted directed graph with efficient shortest path queries and edge additions in real time.

Hard
2646

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…

Hard
2662

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.

Medium
2685

Count the Number of Complete Components

Determine the number of complete connected components in an undirected graph using efficient traversal techniques and gr…

Medium
2699

Modify Graph Edge Weights

Modify Graph Edge Weights is a graph problem where you adjust edge weights to match a target shortest path distance.

Hard
2846

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.

Hard
2858

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…

Hard
2876

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…

Hard
2924

Find Champion II

Identify the strongest team in a tournament DAG using graph-driven logic, ensuring correct handling of in-degree zero ch…

Medium
2959

Number of Possible Sets of Closing Branches

Calculate all valid sets of branch closures while keeping remaining branches within maxDistance using bitmask and graph …

Hard
2976

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…

Medium
2977

Minimum Cost to Convert String II

Compute the minimum cost to transform source into target using substring replacements with given costs efficiently using…

Hard
3015

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.

Medium
3017

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…

Hard
3108

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…

Hard
3112

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…

Medium
3123

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.

Hard
3203

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…

Hard
3241

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.

Hard
3243

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…

Medium
3244

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…

Hard
3286

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.

Medium
3310

Remove Methods From Project

Remove suspicious methods in a project that are invoked directly or indirectly from a buggy method using graph traversal…

Medium
3311

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.

Hard
3341

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…

Medium
3342

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.

Medium
3377

Digit Operations to Make Two Integers Equal

Transform n into m using allowed digit operations without creating primes, applying math and graph strategies efficientl…

Medium
3387

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.

Medium
3419

Minimize the Maximum Edge Weight of Graph

Minimize the maximum edge weight in a graph after removing certain edges while ensuring node reachability.

Medium
3435

Frequencies of Shortest Supersequences

Compute all unique shortest common supersequences of given words using graph indegree tracking and topological ordering …

Hard
3493

Properties Graph

Find the number of connected components in an undirected graph formed by properties arrays, using array scanning and has…

Medium
3528

Unit Conversion I

Solve the unit conversion problem by using graph traversal to compute equivalent unit amounts.

Medium
3530

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…

Hard
3532

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.

Medium
3534

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…

Hard
3543

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…

Medium
3547

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.

Hard
3594

Minimum Time to Transport All Individuals

Find the minimum time to transport individuals across a river with dynamic environmental conditions and boat capacity.

Hard
3600

Maximize Spanning Tree Stability with Upgrades

Maximizing the stability of a spanning tree with upgrades requires careful optimization of edge strengths using binary s…

Hard
3604

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.

Medium
3607

Power Grid Maintenance

Determine which power stations remain connected after maintenance using array scanning and hash lookups to track compone…

Medium
3608

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.

Medium
3613

Minimize Maximum Component Cost

Minimize Maximum Component Cost leverages binary search over edge weights to optimize the cost of graph components after…

Medium
3615

Longest Palindromic Path in Graph

Find the longest path in a graph that forms a palindrome using state transition dynamic programming and bitmask techniqu…

Hard
3620

Network Recovery Pathways

Find the maximum recovery cost of valid paths in a directed acyclic graph where some nodes are offline.

Hard

Related Patterns

Graph LeetCode Problems: 141 Solutions