Solved all Graph problems in 100 days
25616
Sep 08, 2024
Sep 08, 2024

I wanted to study graph-related problems and concepts, so I went through all the graph-tagged problems—around 100 in total, excluding non-public and pure tree problems. Graph theory is a broad field with many algorithms and patterns, but I suggest mastering Parts 1 and 2 first, especially depth-first search (DFS) and breadth-first search (BFS). Part 3 covers many applications and combinations of these basics, which are essential to cover for top companies that are highly competitive in the current market.

My previous lists in case you haven't seen:
1.Two pointers:
https://leetcode.com/discuss/study-guide/1688903/solved-all-two-pointers-problems-in-100-days
2.DPs:
https://leetcode.com/discuss/study-guide/1000929/solved-all-dynamic-programming-dp-problems-in-7-months

//===============================================
Part I - Basics of Graph
//===============================================

1-1 Simple DFS/BFS
https://leetcode.com/problems/evaluate-division
https://leetcode.com/problems/keys-and-rooms
https://leetcode.com/problems/get-watched-videos-by-your-friends
https://leetcode.com/problems/find-if-path-exists-in-graph
https://leetcode.com/problems/detonate-the-maximum-bombs

1-2 Count Degrees
https://leetcode.com/problems/find-the-town-judge
https://leetcode.com/problems/minimum-number-of-vertices-to-reach-all-nodes
https://leetcode.com/problems/maximal-network-rank
https://leetcode.com/problems/minimum-degree-of-a-connected-trio-in-a-graph
https://leetcode.com/problems/count-pairs-of-nodes
https://leetcode.com/problems/find-center-of-star-graph
https://leetcode.com/problems/maximum-total-importance-of-roads
https://leetcode.com/problems/node-with-highest-edge-score
https://leetcode.com/problems/maximum-star-sum-of-a-graph
https://leetcode.com/problems/add-edges-to-make-degrees-of-all-nodes-even
https://leetcode.com/problems/find-champion-ii

1-3 Topological Sorting
https://leetcode.com/problems/course-schedule
https://leetcode.com/problems/course-schedule-ii
https://leetcode.com/problems/all-paths-from-source-to-target
https://leetcode.com/problems/find-eventual-safe-states
https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph
https://leetcode.com/problems/course-schedule-iv
https://leetcode.com/problems/strange-printer-ii
https://leetcode.com/problems/parallel-courses-iii
https://leetcode.com/problems/find-all-possible-recipes-from-given-supplies
https://leetcode.com/problems/build-a-matrix-with-conditions

1-4 Connected Component/Union Find (Disjoint-set)
https://leetcode.com/problems/number-of-provinces
https://leetcode.com/problems/redundant-connection
https://leetcode.com/problems/redundant-connection-ii
https://leetcode.com/problems/most-stones-removed-with-same-row-or-column
https://leetcode.com/problems/satisfiability-of-equality-equations
https://leetcode.com/problems/rank-transform-of-a-matrix
https://leetcode.com/problems/number-of-operations-to-make-network-connected
https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable
https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths
https://leetcode.com/problems/process-restricted-friend-requests
https://leetcode.com/problems/find-all-people-with-secret
https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph
https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities
https://leetcode.com/problems/count-the-number-of-complete-components

1-5 Bipartite
https://leetcode.com/problems/is-graph-bipartite
https://leetcode.com/problems/possible-bipartition

//===============================================
Part II - Medium level topics of Graph
//===============================================

2-1 BFS Variants (0-1 BFS, multi-source BFS)
https://leetcode.com/problems/minimum-height-trees
https://leetcode.com/problems/minimize-malware-spread
https://leetcode.com/problems/minimize-malware-spread-ii
https://leetcode.com/problems/maximum-candies-you-can-get-from-boxes

2-2 Shortest Path - Dijkstra Algorithm
https://leetcode.com/problems/network-delay-time
https://leetcode.com/problems/reachable-nodes-in-subdivided-graph
https://leetcode.com/problems/path-with-maximum-probability
https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid
https://leetcode.com/problems/number-of-restricted-paths-from-first-to-last-node
https://leetcode.com/problems/minimum-cost-to-reach-destination-in-time
https://leetcode.com/problems/number-of-ways-to-arrive-at-destination
https://leetcode.com/problems/the-time-when-the-network-becomes-idle
https://leetcode.com/problems/second-minimum-time-to-reach-destination
https://leetcode.com/problems/minimum-weighted-subgraph-with-the-required-paths
https://leetcode.com/problems/minimum-obstacle-removal-to-reach-corner
https://leetcode.com/problems/minimum-cost-of-a-path-with-special-roads
https://leetcode.com/problems/minimum-time-to-visit-a-cell-in-a-grid
https://leetcode.com/problems/modify-graph-edge-weights

2-3 Shortest Path - Bellman–Ford Algorithm
https://leetcode.com/problems/shortest-path-with-alternating-colors
https://leetcode.com/problems/cheapest-flights-within-k-stops

2-4 Shortest Path - Floyd–Warshall Algorithm
https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
https://leetcode.com/problems/design-graph-with-shortest-path-calculator
https://leetcode.com/problems/number-of-possible-sets-of-closing-branches
https://leetcode.com/problems/minimum-cost-to-convert-string-i
https://leetcode.com/problems/minimum-cost-to-convert-string-ii
https://leetcode.com/problems/count-the-number-of-houses-at-a-certain-distance-i

2-5 Cycle Detection
https://leetcode.com/problems/largest-color-value-in-a-directed-graph
https://leetcode.com/problems/maximum-employees-to-be-invited-to-a-meeting
https://leetcode.com/problems/find-closest-node-to-given-two-nodes
https://leetcode.com/problems/longest-cycle-in-a-graph
https://leetcode.com/problems/shortest-cycle-in-a-graph
https://leetcode.com/problems/count-visited-nodes-in-a-directed-graph

2-6 Minimum Spanning Tree - Kruskal's Algorithm
https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree
https://leetcode.com/problems/min-cost-to-connect-all-points

//===============================================
Part III - Rare/Advanced topics of Graph
//===============================================

3-1 Euler Tour
https://leetcode.com/problems/reconstruct-itinerary
https://leetcode.com/problems/valid-arrangement-of-pairs

3-2 De Bruijn Sequence
https://leetcode.com/problems/cracking-the-safe

3-3 Game on Graph
https://leetcode.com/problems/cat-and-mouse
https://leetcode.com/problems/cat-and-mouse-ii

3-4 Graph Cloning
https://leetcode.com/problems/clone-graph

3-5 Construction
https://leetcode.com/problems/maximum-score-of-a-node-sequence
https://leetcode.com/problems/couples-holding-hands

3-6 Hamilton Cycle/Travelling Sellsman
https://leetcode.com/problems/shortest-path-visiting-all-nodes

3-7 Tarjan's Algorithm
https://leetcode.com/problems/critical-connections-in-a-network

3-8 DP applications
https://leetcode.com/problems/maximum-path-quality-of-a-graph
https://leetcode.com/problems/parallel-courses-ii
https://leetcode.com/problems/flower-planting-with-no-adjacent
https://leetcode.com/problems/loud-and-rich
https://leetcode.com/problems/longest-increasing-path-in-a-matrix
https://leetcode.com/problems/number-of-increasing-paths-in-a-grid

3-9 Ad-Hoc
https://leetcode.com/problems/number-of-ways-to-reconstruct-a-tree
https://leetcode.com/problems/divide-nodes-into-the-maximum-number-of-groups
https://leetcode.com/problems/count-the-number-of-houses-at-a-certain-distance-ii

Comments (18)