Graph Traversal (BFS & DFS)
Trees & GraphsShortest paths, flood fills, and connected components in arbitrary networks
166 problems·3 Easy·84 Medium·79 Hard
Pattern Study Guide & Cheat Sheet▼
Explore vertices and edges in arbitrary networks using BFS (for unweighted shortest paths) or DFS (for connectivity, cycle detection, and component exploration).
Core Invariant: Visited Set Invariant: A node must be marked visited AT THE MOMENT IT IS ENQUEUED (for BFS) or entered (for DFS). Marking on pop causes the same node to be enqueued multiple times exponentially.
Recognize it (Keywords & Signals)
- Shortest path / minimum transformations in unweighted graph
- Clone graph / serialize network
- Connected components / bipartite graph check
- Word ladder (transform word A to B)
- Detect cycle in directed or undirected graph
When NOT to use
Weighted graph with varying edge costs (use Dijkstra for non-negative weights, Bellman-Ford for negative weights).
How to solve (Step-by-step)
- 1.Construct adjacency list: `graph = collections.defaultdict(list)`.
- 2.Choose traversal: BFS (`deque`) for shortest path; DFS (recursion) for exploration/cycles.
- 3.Initialize `visited = set([start_node])` and `queue = deque([(start_node, 0)])`.
- 4.While queue is not empty: pop `curr, dist`.
- 5.If `curr == target`, return `dist`.
- 6.For each `neighbor in graph[curr]`: if `neighbor not in visited`, mark `visited.add(neighbor)` and `queue.append((neighbor, dist + 1))`.
Watch for (Interview Traps)
- Marking visited on pop instead of enqueue: causes catastrophic duplicate queue insertions and TLE
- Directed vs undirected: adding bidirectional edges when edges are strictly directed
- Not handling disconnected graph components (need a wrapper loop over all nodes `0..V-1`)
BFS Shortest Path (Unweighted Graph)
from collections import deque, defaultdict
def bfs_shortest_path(edges: list[list[int]], start: int, target: int) -> int:
# 1. Build adjacency list
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
# 2. Queue stores (current_node, distance)
queue = deque([(start, 0)])
visited = {start} # ALWAYS mark visited at enqueue time
while queue:
curr, dist = queue.popleft()
if curr == target:
return dist
for neighbor in graph[curr]:
if neighbor not in visited:
visited.add(neighbor)
queue.append((neighbor, dist + 1))
return -1 # Target unreachable- Cost
- O(V + E) visits every vertex and edge once · O(V) for queue and visited set (Linear in graph size for adjacency list representation.)
Canonical problems
#127 Word Ladder: BFS finds shortest sequence of 1-letter word mutations
#133 Clone Graph: DFS/BFS with hash map mapping original node to cloned copy
#785 Is Graph Bipartite?: 2-color BFS/DFS to verify no adjacent nodes share same color
#200 Number of Islands: Graph traversal over grid adjacency
⌘K
Medium·25 companies·Max freq 100%·Acc 64.4%
Tower Research CapitalTower Research CapitalUrban Company+22
Medium·22 companies·Max freq 100%·Acc 42.2%
HTCMakeMyTripStripe+19
Hard·20 companies·Max freq 93%·Acc 56.8%
DoorDashWeRideDuolingo+17
Medium·14 companies·Max freq 100%·Acc 61.2%
Urban CompanyServiceNowNeetCode 150+11
Medium·12 companies·Max freq 100%·Acc 71.3%
DirectiNeetCode 150NeetCode 150+9
Medium·11 companies·Max freq 100%·Acc 66.9%
Akuna CapitalPhonePeIBM+8
Hard·11 companies·Max freq 88%·Acc 0.6%
KLA TencorInMobiAkuna Capital+8
Hard·11 companies·Max freq 77%·Acc 60.0%
UberMathWorksMeesho+8
Medium·10 companies·Max freq 100%·Acc 65.1%
XGeneral MotorsX+7
Medium·10 companies·Max freq 92%·Acc 57.0%
VerilyZeta GlobalDocusign+7
Medium·8 companies·Max freq 89%·Acc 61.8%
AsanaPalantirOracle+5
Medium·7 companies·Max freq 100%·Acc 0.5%
Sumo LogicSumo LogicCleverTap+4
Hard·7 companies·Max freq 65%·Acc 41.9%
PhonePeDatabricksAirbnb+4
Hard·7 companies·Max freq 63%·Acc 0.6%
CitadelSquarepoint CapitalPalo Alto Networks+4
Hard·6 companies·Max freq 100%·Acc 0.5%
Hudson River TradingHudson River TradingTarget+3
Hard·6 companies·Max freq 75%·Acc 68.2%
DE ShawTuringGoogle+3
Hard·6 companies·Max freq 63%·Acc 66.9%
UberAccentureGoogle+3
Medium·5 companies·Max freq 63%·Acc 83.7%
BloombergNetflixAmazon+2
Medium·5 companies·Max freq 63%·Acc 0.5%
SnapSnapAmazon+2
Hard·5 companies·Max freq 60%·Acc 61.8%
NutanixMicrosoftOracle+2
Hard·5 companies·Max freq 56%·Acc 57.2%
JuspayLinkedInGoogle+2
Hard·5 companies·Max freq 56%·Acc 66.0%
CitadelMetaAmazon+2
Hard·5 companies·Max freq 50%·Acc 0.7%
UberDE ShawMeta+2
Medium·5 companies·Max freq 50%·Acc 66.0%
TikTokMicrosoftAmazon+2
Medium·5 companies·Max freq 38%·Acc 70.7%
GoogleBloombergMeta+2
Medium·5 companies·Max freq 38%·Acc 65.4%
MicrosoftAmazonUber+2
Medium·5 companies·Max freq 25%·Acc 37.6%
MetaAmazonGoogle+2
Hard·4 companies·Max freq 100%·Acc 57.0%
ServiceNowOracleMicrosoft+1
Medium·4 companies·Max freq 89%·Acc 53.5%
GuidewireBoltAmazon+1
Hard·4 companies·Max freq 88%·Acc 67.2%
AirbnbLyftBloomberg+1
Medium·4 companies·Max freq 88%·Acc 53.1%
JuspayAmazonBloomberg+1
Medium·4 companies·Max freq 75%·Acc 81.7%
AirbnbGoogleMeta+1
Medium·4 companies·Max freq 65%·Acc 55.5%
UberGoogleBloomberg+1
Medium·4 companies·Max freq 63%·Acc 43.7%
SalesforceAppleMicrosoft+1
Medium·4 companies·Max freq 63%·Acc 62.3%
OracleGoogleAmazon+1
Medium·4 companies·Max freq 63%·Acc 63.2%
AtlassianAmazonMicrosoft+1
Hard·4 companies·Max freq 63%·Acc 59.6%
AtlassianAmazonMicrosoft+1
Hard·4 companies·Max freq 63%·Acc 56.1%
AtlassianMicrosoftGoogle+1
Hard·4 companies·Max freq 38%·Acc 66.6%
UberAmazonMeta+1
Medium·4 companies·Max freq 16%·Acc 80.8%
MicrosoftMetaAmazon+1
Medium·3 companies·Max freq 100%·Acc 55.8%
Deutsche BankAtlassianAmazon
Medium·3 companies·Max freq 60%·Acc 61.7%
RipplingUberGoogle
Medium·3 companies·Max freq 52%·Acc 67.6%
UberAmazonGoogle
Hard·3 companies·Max freq 25%·Acc 63.4%
UberGoogleMicrosoft
Medium·3 companies·Max freq 16%·Acc 61.9%
MicrosoftAmazonGoogle
Hard·3 companies·Max freq 13%·Acc 66.2%
AmazonMicrosoftGoogle
Hard·2 companies·Max freq 100%·Acc 0.4%
Hudson River TradingHudson River Trading
Medium·2 companies·Max freq 100%·Acc 0.7%
Hudson River TradingHudson River Trading
Medium·2 companies·Max freq 77%·Acc 61.0%
FlipkartGoldman Sachs
Hard·2 companies·Max freq 75%·Acc 51.6%
Oscar HealthGoogle
Hard·2 companies·Max freq 69%·Acc 44.6%
GoDaddyAmazon
Medium·2 companies·Max freq 38%·Acc 31.0%
MicrosoftGoogle
Medium·1 companies·Max freq 63%·Acc 58.1%
Oracle
Hard·1 companies·Max freq 63%·Acc 23.8%
Oracle
Hard·1 companies·Max freq 25%·Acc 43.6%
Amazon
Medium·1 companies·Max freq 25%·Acc 41.5%
Google
# | Problem | Difficulty | Top Companies↓ | Frequency | Acceptance | |
|---|---|---|---|---|---|---|
| #200 | Number of Islands ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 100% | 64.7% | ||
| #994 | Rotting Oranges ArrayBreadth-First SearchMatrix | Medium | 100% | 59.0% | ||
| #207 | Course Schedule Depth-First SearchBreadth-First SearchGraph TheoryTopological SortDirected Acyclic Graph | Medium | 100% | 51.8% | ||
| #127 | Word Ladder Hash TableStringBreadth-First SearchBidirectional Search | Hard | 100% | 46.0% | ||
| #210 | Course Schedule II Depth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Medium | 100% | 55.9% | ||
| #332 | Reconstruct Itinerary ArrayStringDepth-First SearchGraph TheorySortingHeap (Priority Queue)Eulerian CircuitEulerian PathSemi-Eulerian Graph | Hard | 100% | 44.7% | ||
| #399 | Evaluate Division ArrayStringDepth-First SearchBreadth-First SearchUnion-FindGraph TheoryShortest PathBellman–Ford AlgorithmFloyd–Warshall Algorithm | Medium | 100% | 64.4% | ||
| #269 | Alien Dictionary ArrayStringDepth-First SearchBreadth-First SearchGraph TheoryTopological SortDirected Acyclic Graph | Hard | 100% | 37.3% | ||
| #787 | Cheapest Flights Within K Stops Dynamic ProgrammingDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)Shortest Path | Medium | 100% | 42.2% | ||
| #695 | Max Area of Island ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 100% | 74.1% | ||
| #133 | Clone Graph Hash TableDepth-First SearchBreadth-First SearchGraph Theory | Medium | 100% | 65.7% | ||
| #329 | Longest Increasing Path in a Matrix ArrayDynamic ProgrammingDepth-First SearchBreadth-First SearchGraph TheoryTopological SortMemoizationMatrixDirected Acyclic Graph | Hard | 93% | 56.8% | ||
| #752 | Open the Lock ArrayHash TableStringBreadth-First SearchBidirectional Search | Medium | 100% | 0.6% | ||
| #126 | Word Ladder II Hash TableStringBacktrackingBreadth-First SearchBidirectional Search | Hard | 100% | 27.8% | ||
| #130 | Surrounded Regions ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 87% | 0.5% | ||
| #417 | Pacific Atlantic Water Flow ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 100% | 61.2% | ||
| #286 | Walls and Gates ArrayBreadth-First SearchMatrix | Medium | 100% | 64.1% | ||
| #2603 | Collect Coins in a Tree ArrayTreeGraph TheoryTopological Sort | Hard | 100% | 39.5% | ||
| #1584 | Min Cost to Connect All Points ArrayUnion-FindGraph TheoryMinimum Spanning TreePrim's AlgorithmKruskal's AlgorithmBorůvka's Algorithm | Medium | 100% | 71.3% | ||
| #277 | Find the Celebrity Two PointersGraph TheoryInteractive | Medium | 100% | 49.0% | ||
| #886 | Possible Bipartition Depth-First SearchBreadth-First SearchUnion-FindGraph TheoryGraph ColoringBipartite Graph | Medium | 75% | 52.8% | ||
| #261 | Graph Valid Tree Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 100% | 50.1% | ||
| #1319 | Number of Operations to Make Network Connected Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 100% | 66.9% | ||
| #743 | Network Delay Time Depth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)Shortest PathDijkstra's Algorithm | Medium | 100% | 61.0% | ||
| #785 | Is Graph Bipartite? Depth-First SearchBreadth-First SearchUnion-FindGraph TheoryGraph ColoringBipartite Graph | Medium | 88% | 59.6% | ||
| #1192 | Critical Connections in a Network Depth-First SearchGraph TheoryBiconnected ComponentBridge (Graph) | Hard | 88% | 0.6% | ||
| #2858 | Minimum Edge Reversals So Every Node Is Reachable Dynamic ProgrammingDepth-First SearchBreadth-First SearchGraph Theory | Hard | 77% | 60.0% | ||
| #684 | Redundant Connection Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 75% | 0.7% | ||
| #841 | Keys and Rooms Depth-First SearchBreadth-First SearchGraph Theory | Medium | 100% | 76.0% | ||
| #323 | Number of Connected Components in an Undirected Graph Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 100% | 65.1% | ||
| #2050 | Parallel Courses III ArrayDynamic ProgrammingGraph TheoryTopological SortDirected Acyclic Graph | Hard | 100% | 66.8% | ||
| #924 | Minimize Malware Spread ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 100% | 43.3% | ||
| #2115 | Find All Possible Recipes from Given Supplies ArrayHash TableStringGraph TheoryTopological SortDirected Acyclic Graph | Medium | 92% | 57.0% | ||
| #305 | Number of Islands II ArrayHash TableUnion-Find | Hard | 90% | 40.7% | ||
| #631 | Design Excel Sum Formula ArrayHash TableStringGraph TheoryDesignTopological SortMatrix | Hard | 100% | 39.6% | ||
| #547 | Number of Provinces Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 100% | 70.7% | ||
| #3650 | Minimum Cost Path with Edge Reversals Graph TheoryHeap (Priority Queue)Shortest Path | Medium | 89% | 61.8% | ||
| #997 | Find the Town Judge ArrayHash TableGraph Theory | Easy | 100% | 50.9% | ||
| #990 | Satisfiability of Equality Equations ArrayStringUnion-FindGraph Theory | Medium | 100% | 0.5% | ||
| #310 | Minimum Height Trees Depth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Medium | 100% | 42.6% | ||
| #2360 | Longest Cycle in a Graph Depth-First SearchBreadth-First SearchGraph TheoryTopological SortKosaraju's AlgorithmTarjan's SCC Algorithm | Hard | 88% | 50.9% | ||
| #2101 | Detonate the Maximum Bombs ArrayMathDepth-First SearchBreadth-First SearchGraph TheoryGeometry | Medium | 88% | 50.3% | ||
| #834 | Sum of Distances in Tree Dynamic ProgrammingTreeDepth-First SearchGraph TheoryDP on Trees | Hard | 85% | 65.7% | ||
| #1136 | Parallel Courses Graph TheoryTopological SortDirected Acyclic Graph | Medium | 81% | 62.3% | ||
| #3607 | Power Grid Maintenance ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindGraph TheoryHeap (Priority Queue)Ordered Set | Medium | 75% | 56.1% | ||
| #851 | Loud and Rich ArrayDepth-First SearchGraph TheoryTopological SortDirected Acyclic Graph | Medium | 65% | 63.8% | ||
| #1928 | Minimum Cost to Reach Destination in Time ArrayDynamic ProgrammingGraph TheoryDijkstra's Algorithm | Hard | 65% | 41.9% | ||
| #765 | Couples Holding Hands GreedyDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 63% | 0.6% | ||
| #802 | Find Eventual Safe States Depth-First SearchBreadth-First SearchGraph TheoryTopological SortKosaraju's AlgorithmTarjan's SCC Algorithm | Medium | 50% | 71.2% | ||
| #1245 | Tree Diameter TreeDepth-First SearchBreadth-First SearchGraph TheoryTopological SortDP on Trees | Medium | 39% | 61.3% | ||
| #2246 | Longest Path With Different Adjacent Characters ArrayStringTreeDepth-First SearchGraph TheoryTopological Sort | Hard | 100% | 0.5% | ||
| #2467 | Most Profitable Path in a Tree ArrayTreeDepth-First SearchBreadth-First SearchGraph Theory | Medium | 88% | 67.3% | ||
| #3108 | Minimum Cost Walk in Weighted Graph ArrayBit ManipulationUnion-FindGraph Theory | Hard | 75% | 68.2% | ||
| #2493 | Divide Nodes Into the Maximum Number of Groups Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 63% | 66.9% | ||
| #1462 | Course Schedule IV Depth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Medium | 50% | 60.0% | ||
| #2065 | Maximum Path Quality of a Graph ArrayBacktrackingGraph Theory | Hard | 92% | 62.6% | ||
| #797 | All Paths From Source to Target BacktrackingDepth-First SearchBreadth-First SearchGraph TheoryDirected Acyclic Graph | Medium | 63% | 83.7% | ||
| #2316 | Count Unreachable Pairs of Nodes in an Undirected Graph Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 63% | 0.5% | ||
| #2127 | Maximum Employees to Be Invited to a Meeting ArrayDynamic ProgrammingDepth-First SearchGraph TheoryTopological SortKosaraju's AlgorithmTarjan's SCC Algorithm | Hard | 60% | 61.8% | ||
| #1857 | Largest Color Value in a Directed Graph Hash TableStringDynamic ProgrammingGraph TheoryTopological SortMemoizationCountingDirected Acyclic Graph | Hard | 56% | 57.2% | ||
| #1203 | Sort Items by Groups Respecting Dependencies Depth-First SearchBreadth-First SearchGraph TheoryTopological SortDirected Acyclic Graph | Hard | 56% | 66.0% | ||
| #505 | The Maze II ArrayDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest PathDijkstra's AlgorithmHeuristic SearchA* Search | Medium | 54% | 55.2% | ||
| #1579 | Remove Max Number of Edges to Keep Graph Fully Traversable Union-FindGraph Theory | Hard | 50% | 0.7% | ||
| #1466 | Reorder Routes to Make All Paths Lead to the City Zero Depth-First SearchBreadth-First SearchGraph Theory | Medium | 50% | 66.0% | ||
| #1514 | Path with Maximum Probability ArrayGraph TheoryHeap (Priority Queue)Shortest PathDijkstra's Algorithm | Medium | 50% | 65.6% | ||
| #1971 | Find if Path Exists in Graph Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Easy | 38% | 55.5% | ||
| #3532 | Path Existence Queries in a Graph I ArrayHash TableBinary SearchUnion-FindGraph Theory | Medium | 38% | 70.7% | ||
| #2477 | Minimum Fuel Cost to Report to the Capital TreeDepth-First SearchBreadth-First SearchGraph Theory | Medium | 38% | 65.4% | ||
| #1976 | Number of Ways to Arrive at Destination Dynamic ProgrammingGraph TheoryTopological SortShortest PathDijkstra's Algorithm | Medium | 25% | 37.6% | ||
| #2608 | Shortest Cycle in a Graph Breadth-First SearchGraph Theory | Hard | 100% | 40.0% | ||
| #3203 | Find Minimum Diameter After Merging Two Trees TreeDepth-First SearchBreadth-First SearchGraph Theory | Hard | 100% | 57.0% | ||
| #1311 | Get Watched Videos by Your Friends ArrayHash TableBreadth-First SearchGraph TheorySorting | Medium | 89% | 53.5% | ||
| #1298 | Maximum Candies You Can Get from Boxes ArrayBreadth-First SearchGraph Theory | Hard | 88% | 67.2% | ||
| #2359 | Find Closest Node to Given Two Nodes Depth-First SearchGraph Theory | Medium | 88% | 53.1% | ||
| #1557 | Minimum Number of Vertices to Reach All Nodes Graph TheoryDirected Acyclic Graph | Medium | 75% | 81.7% | ||
| #3341 | Find Minimum Time to Reach Last Room I ArrayGraph TheoryHeap (Priority Queue)MatrixShortest Path | Medium | 65% | 55.5% | ||
| #3613 | Minimize Maximum Component Cost Binary SearchUnion-FindGraph TheorySorting | Medium | 63% | 43.7% | ||
| #2192 | All Ancestors of a Node in a Directed Acyclic Graph Depth-First SearchBreadth-First SearchGraph TheoryTopological SortDirected Acyclic Graph | Medium | 63% | 62.3% | ||
| #2976 | Minimum Cost to Convert String I ArrayStringGraph TheoryShortest Path | Medium | 63% | 63.2% | ||
| #2977 | Minimum Cost to Convert String II ArrayStringDynamic ProgrammingGraph TheoryTrieShortest Path | Hard | 63% | 59.6% | ||
| #2577 | Minimum Time to Visit a Cell In a Grid ArrayBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest Path | Hard | 63% | 56.1% | ||
| #847 | Shortest Path Visiting All Nodes Dynamic ProgrammingBit ManipulationBreadth-First SearchGraph TheoryBitmask | Hard | 38% | 66.1% | ||
| #1489 | Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree Union-FindGraph TheorySortingMinimum Spanning TreeStrongly Connected ComponentPrim's AlgorithmKruskal's AlgorithmBorůvka's Algorithm | Hard | 38% | 66.6% | ||
| #1791 | Find Center of Star Graph Graph Theory | Easy | 38% | 86.6% | ||
| #2685 | Count the Number of Complete Components Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 16% | 80.8% | ||
| #3534 | Path Existence Queries in a Graph II ArrayTwo PointersBinary SearchDynamic ProgrammingGreedyBit ManipulationGraph TheorySorting | Hard | 15% | 64.6% | ||
| #2039 | The Time When the Network Becomes Idle ArrayBreadth-First SearchGraph Theory | Medium | 100% | 55.8% | ||
| #2497 | Maximum Star Sum of a Graph ArrayGreedyGraph TheorySortingHeap (Priority Queue) | Medium | 88% | 42.5% | ||
| #3387 | Maximize Amount After Two Days of Conversions ArrayStringDepth-First SearchBreadth-First SearchGraph Theory | Medium | 60% | 61.7% | ||
| #1632 | Rank Transform of a Matrix ArrayUnion-FindGraph TheoryTopological SortSortingMatrix | Hard | 56% | 42.4% | ||
| #3342 | Find Minimum Time to Reach Last Room II ArrayGraph TheoryHeap (Priority Queue)MatrixShortest Path | Medium | 52% | 67.6% | ||
| #1494 | Parallel Courses II Dynamic ProgrammingBit ManipulationGraph TheoryBitmaskDirected Acyclic Graph | Hard | 50% | 31.1% | ||
| #2097 | Valid Arrangement of Pairs ArrayDepth-First SearchGraph TheoryEulerian CircuitEulerian PathSemi-Eulerian Graph | Hard | 50% | 66.6% | ||
| #1361 | Validate Binary Tree Nodes TreeDepth-First SearchBreadth-First SearchUnion-FindGraph TheoryBinary Tree | Medium | 25% | 44.2% | ||
| #2421 | Number of Good Paths ArrayHash TableTreeUnion-FindGraph TheorySorting | Hard | 25% | 56.5% | ||
| #1697 | Checking Existence of Edge Length Limited Paths ArrayTwo PointersUnion-FindGraph TheorySorting | Hard | 25% | 63.4% | ||
| #3243 | Shortest Distance After Road Addition Queries I ArrayBreadth-First SearchGraph Theory | Medium | 16% | 61.9% | ||
| #3286 | Find a Safe Walk Through a Grid ArrayBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest Path | Medium | 15% | 55.3% | ||
| #3310 | Remove Methods From Project Depth-First SearchBreadth-First SearchGraph Theory | Medium | 13% | 0.7% | ||
| #3600 | Maximize Spanning Tree Stability with Upgrades Binary SearchGreedyUnion-FindGraph TheoryMinimum Spanning Tree | Hard | 13% | 66.2% | ||
| #2368 | Reachable Nodes With Restrictions ArrayHash TableTreeDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 100% | 60.6% | ||
| #2508 | Add Edges to Make Degrees of All Nodes Even Hash TableGraph Theory | Hard | 100% | 0.4% | ||
| #2285 | Maximum Total Importance of Roads GreedyGraph TheorySortingHeap (Priority Queue) | Medium | 100% | 0.7% | ||
| #3123 | Find Edges in Shortest Paths Depth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)Shortest Path | Hard | 100% | 46.9% | ||
| #928 | Minimize Malware Spread II ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 100% | 45.8% | ||
| #3710 | Maximum Partition Factor ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 93% | 32.1% | ||
| #2642 | Design Graph With Shortest Path Calculator Graph TheoryDesignHeap (Priority Queue)Shortest Path | Hard | 88% | 65.4% | ||
| #2328 | Number of Increasing Paths in a Grid ArrayDynamic ProgrammingDepth-First SearchBreadth-First SearchGraph TheoryTopological SortMemoizationMatrix | Hard | 88% | 57.3% | ||
| #1377 | Frog Position After T Seconds TreeDepth-First SearchBreadth-First SearchGraph Theory | Hard | 83% | 38.7% | ||
| #2093 | Minimum Cost to Reach City With Discounts Graph TheoryHeap (Priority Queue)Shortest PathDijkstra's Algorithm | Medium | 77% | 61.0% | ||
| #1724 | Checking Existence of Edge Length Limited Paths II Depth-First SearchUnion-FindGraph TheoryDesignSortingHeap (Priority Queue)Minimum Spanning Tree | Hard | 75% | 51.6% | ||
| #1042 | Flower Planting With No Adjacent Depth-First SearchBreadth-First SearchGraph TheoryGraph Coloring | Medium | 70% | 53.9% | ||
| #1761 | Minimum Degree of a Connected Trio in a Graph Graph TheoryEnumeration | Hard | 69% | 44.6% | ||
| #3608 | Minimum Time for K Connected Components Binary SearchUnion-FindGraph TheorySorting | Medium | 54% | 45.7% | ||
| #2307 | Check for Contradictions in Equations ArrayStringDepth-First SearchUnion-FindGraph Theory | Hard | 50% | 44.0% | ||
| #2204 | Distance to a Cycle in Undirected Graph Depth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Hard | 38% | 73.9% | ||
| #444 | Sequence Reconstruction ArrayGraph TheoryTopological SortDirected Acyclic Graph | Medium | 38% | 31.0% | ||
| #1820 | Maximum Number of Accepted Invitations ArrayDepth-First SearchGraph TheoryMatrixMaximum FlowMaximum MatchingBipartite GraphEdmonds–Karp AlgorithmMPM AlgorithmPush-Relabel AlgorithmMatching (Graph)Flow NetworkDinic's Algorithm | Medium | 38% | 52.7% | ||
| #3377 | Digit Operations to Make Two Integers Equal MathGraph TheoryHeap (Priority Queue)Number TheoryShortest Path | Medium | 38% | 31.0% | ||
| #1810 | Minimum Path Cost in a Hidden Grid ArrayDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixInteractiveShortest Path | Medium | 27% | 59.0% | ||
| #1168 | Optimize Water Distribution in a Village Union-FindGraph TheoryHeap (Priority Queue)Minimum Spanning TreePrim's AlgorithmKruskal's AlgorithmBorůvka's Algorithm | Hard | 25% | 65.6% | ||
| #2924 | Find Champion II Graph Theory | Medium | 25% | 70.4% | ||
| #2290 | Minimum Obstacle Removal to Reach Corner ArrayBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest Path0-1 BFSDijkstra's Algorithm | Hard | 25% | 70.9% | ||
| #2076 | Process Restricted Friend Requests Union-FindGraph Theory | Hard | 25% | 61.0% | ||
| #3419 | Minimize the Maximum Edge Weight of Graph Binary SearchDepth-First SearchBreadth-First SearchGraph TheoryShortest Path | Medium | 25% | 45.1% | ||
| #2045 | Second Minimum Time to Reach Destination Breadth-First SearchGraph TheoryShortest PathDijkstra's AlgorithmK Shortest Path | Hard | 13% | 0.6% | ||
| #3620 | Network Recovery Pathways ArrayBinary SearchDynamic ProgrammingGraph TheoryTopological SortHeap (Priority Queue)Shortest Path | Hard | 13% | 50.9% | ||
| #2876 | Count Visited Nodes in a Directed Graph Dynamic ProgrammingDepth-First SearchGraph TheoryTopological SortMemoizationKosaraju's AlgorithmTarjan's SCC Algorithm | Hard | 100% | 31.1% | ||
| #2662 | Minimum Cost of a Path With Special Roads ArrayGraph TheoryHeap (Priority Queue)Shortest Path | Medium | 100% | 43.5% | ||
| #3435 | Frequencies of Shortest Supersequences ArrayStringBit ManipulationGraph TheoryTopological SortEnumeration | Hard | 100% | 22.8% | ||
| #3385 | Minimum Time to Break Locks II ArrayBreadth-First SearchGraph Theory | Hard | 100% | 45.8% | ||
| #2374 | Node With Highest Edge Score Hash TableGraph Theory | Medium | 88% | 49.5% | ||
| #1916 | Count Ways to Build Rooms in an Ant Colony ArrayMathDynamic ProgrammingTreeDepth-First SearchGraph TheoryTopological SortCombinatoricsDP on TreesFermat's Little Theorem | Hard | 88% | 51.8% | ||
| #3787 | Find Diameter Endpoints of a Tree TreeBreadth-First SearchGraph Theory | Medium | 84% | 66.9% | ||
| #3383 | Minimum Runes to Add to Cast Spell ArrayDepth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Hard | 75% | 44.7% | ||
| #3015 | Count the Number of Houses at a Certain Distance I Breadth-First SearchGraph TheoryPrefix Sum | Medium | 63% | 58.1% | ||
| #3017 | Count the Number of Houses at a Certain Distance II Graph TheoryPrefix Sum | Hard | 63% | 23.8% | ||
| #3528 | Unit Conversion I Depth-First SearchBreadth-First SearchGraph Theory | Medium | 52% | 54.1% | ||
| #1719 | Number Of Ways To Reconstruct A Tree ArrayHash TableTreeGraph TheorySimulation | Hard | 50% | 46.2% | ||
| #3481 | Apply Substitutions ArrayHash TableStringDepth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Medium | 43% | 77.9% | ||
| #1615 | Maximal Network Rank Graph Theory | Medium | 38% | 66.1% | ||
| #2203 | Minimum Weighted Subgraph With the Required Paths Graph TheoryHeap (Priority Queue)Shortest Path | Hard | 38% | 42.7% | ||
| #2242 | Maximum Score of a Node Sequence ArrayGraph TheorySortingEnumeration | Hard | 26% | 40.3% | ||
| #3535 | Unit Conversion II ArrayMathDepth-First SearchBreadth-First SearchGraph Theory | Medium | 25% | 65.8% | ||
| #1135 | Connecting Cities With Minimum Cost Union-FindGraph TheoryHeap (Priority Queue)Minimum Spanning Tree | Medium | 25% | 63.6% | ||
| #1782 | Count Pairs Of Nodes ArrayHash TableTwo PointersBinary SearchGraph TheorySortingCounting | Hard | 25% | 42.9% | ||
| #2297 | Jump Game VIII ArrayDynamic ProgrammingStackGraph TheoryMonotonic StackShortest Path | Medium | 25% | 45.9% | ||
| #2123 | Minimum Operations to Remove Adjacent Ones in Matrix ArrayDepth-First SearchGraph TheoryMatrixEdmonds–Karp AlgorithmMPM AlgorithmPush-Relabel AlgorithmFlow NetworkDinic's Algorithm | Hard | 25% | 43.6% | ||
| #2714 | Find Shortest Path with K Hops Graph TheoryHeap (Priority Queue)Shortest Path | Hard | 25% | 68.7% | ||
| #753 | Cracking the Safe StringDepth-First SearchGraph TheoryEulerian CircuitEulerian PathEulerian Graph | Hard | 25% | 58.5% | ||
| #1728 | Cat and Mouse II ArrayMathDynamic ProgrammingGraph TheoryTopological SortMemoizationMinimaxMatrixGame TheoryZero-Sum Game | Hard | 25% | 40.4% | ||
| #1786 | Number of Restricted Paths From First to Last Node Dynamic ProgrammingGraph TheoryTopological SortHeap (Priority Queue)Shortest PathDijkstra's Algorithm | Medium | 25% | 41.5% | ||
| #2392 | Build a Matrix With Conditions ArrayGraph TheoryTopological SortMatrixDirected Acyclic Graph | Hard | 25% | 79.3% | ||
| #685 | Redundant Connection II Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 25% | 36.4% | ||
| #1059 | All Paths from Source Lead to Destination Graph TheoryTopological SortKosaraju's AlgorithmTarjan's SCC Algorithm | Medium | 25% | 37.3% | ||
| #1591 | Strange Printer II ArrayGraph TheoryTopological SortMatrixDirected Acyclic Graph | Hard | 25% | 61.1% | ||
| #1153 | String Transforms Into Another String Hash TableStringGraph Theory | Hard | 25% | 34.6% | ||
| #1548 | The Most Similar Path in a Graph ArrayStringDynamic ProgrammingGraph Theory | Hard | 25% | 59.5% | ||
| #2077 | Paths in Maze That Lead to Same Room Graph Theory | Medium | 25% | 56.8% | ||
| #2371 | Minimize Maximum Value in a Grid ArrayUnion-FindGraph TheoryTopological SortSortingMatrix | Hard | 25% | 70.1% | ||
| #3493 | Properties Graph ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 13% | 49.1% | ||
| #3928 | Minimum Cost to Buy Apples II ArrayGraph TheoryHeap (Priority Queue)Shortest Path | Hard | 13% | 31.8% | ||
| #3547 | Maximum Sum of Edge Values in a Graph MathGreedyGraph Theory | Hard | 13% | 37.0% | ||
| #2699 | Modify Graph Edge Weights Graph TheoryHeap (Priority Queue)Shortest Path | Hard | 13% | 55.6% | ||
| #499 | The Maze III ArrayStringDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest PathDijkstra's AlgorithmHeuristic SearchA* Search | Hard | 13% | 52.5% | ||
| #3615 | Longest Palindromic Path in Graph StringDynamic ProgrammingBit ManipulationGraph TheoryBitmask | Hard | 13% | 22.5% |
Showing 166 of 166 problems in Graph Traversal (BFS & DFS)Filtered: All Companies