Graph

Graph

Master graph algorithms with BFS, DFS, shortest paths and more

55 Problems
Intermediate

All Problems

55 problems
1
1. Graph Introduction and Course Overview
Introduction to Graph Data Structures, including nodes, edges, and the course overview.
Easy
Not Attempted
Video
2
2 Types of graphs
Overview of various types of graphs: Directed vs Undirected, Weighted vs Unweighted.
Easy
Not Attempted
Video
3
3 Graph Implementations
Theoretical breakdown of Adjacency Matrix and Adjacency List.
Easy
Not Attempted
Video
4
4 Graph Implementations | Code
Practical coding implementation of Adjacency Matrix and Adjacency List.
Easy
Not Attempted
Video
5
5 Graph Traversal
Building the intuition behind graph traversal techniques (DFS and BFS).
Easy
Not Attempted
Video
6
6. BFS Traversal of Graph
Given a directed graph, return the Breadth First Traversal of this graph starting from node 0.
Easy
Not Attempted
Video
7
7. DFS Traversal of Graph
Given a connected undirected graph, return the Depth First Traversal of this graph starting from node 0.
Easy
Not Attempted
Video
8
8. Number of Provinces
There are n cities. Return the total number of provinces (connected components).
Medium
Not Attempted
Video
9
9. Flood Fill
Perform a flood fill on the image starting from the given pixel. (Note: Outputting modified grid to allow exact array validation against testcases).
Easy
Not Attempted
Video
10
10. Course Schedule II
Return the ordering of courses you should take to finish all courses. If there are multiple valid answers, return any of them.
Medium
Not Attempted
Video
11
11. Steps by Knight
Given a square chessboard of size N x N, the initial position of a Knight and the position of a target. Find out the minimum steps a Knight will take to reach the target position.
Medium
Not Attempted
Video
12
12. Reorder Routes to Make All Paths Lead to the City Zero
There are n cities numbered from 0 to n - 1 and n - 1 roads. You need to reorient some roads such that each city can visit the city 0. Return the minimum number of edges changed.
Medium
Not Attempted
Video
13
13. Cycle Detection Introduction
Detect whether there is a cycle in an undirected graph. (Introductory concept)
Easy
Not Attempted
Video
14
14. Cycle Detection in Undirected Graph using DFS
Detect whether there is a cycle in an undirected graph using Depth First Search (DFS).
Medium
Not Attempted
Video
15
15. Cycle Detection in Undirected Graph using BFS
Detect whether there is a cycle in an undirected graph using Breadth First Search (BFS).
Medium
Not Attempted
Video
16
16. Cycle Detection In Directed Graph Using DFS
Given a Directed Graph with V vertices and E edges, check whether it contains any cycle or not.
Medium
Not Attempted
Video
17
17. Eventual Safe States Introduction
Introduction to identifying safe nodes in a graph. A node is safe if every possible path from it leads to a terminal node (or another safe node) without entering a cycle.
Easy
Not Attempted
Video
18
18. Eventual Safe States Code
Return an array containing all the safe nodes of a directed graph. The answer should be sorted in ascending order.
Medium
Not Attempted
Video
19
19. Longest Cycle in a Graph
You are given a directed graph of n nodes, where each node has at most one outgoing edge. Return the length of the longest cycle. If no cycle exists, return -1.
Hard
Not Attempted
Video
20
20. Topological Sort Introduction
Introduction to Topological Sort in Directed Acyclic Graphs (DAG). Linear ordering of vertices such that for every directed edge u -> v, vertex u comes before v.
Easy
Not Attempted
Video
21
21. Topological Sort Using Kahn's Algorithm
Conceptual explanation of Kahn's Algorithm to efficiently perform topological sorting by tracking the in-degrees of nodes in a Directed Acyclic Graph.
Easy
Not Attempted
Video
22
22. Topological Sort Using BFS Code
Given a Directed Acyclic Graph (DAG) with V vertices and E edges, find any Topological Sorting of that Graph using Breadth-First Search (Kahn's Algorithm).
Medium
Not Attempted
Video
23
23. Topological Sort Using DFS
Given a Directed Acyclic Graph (DAG), return the topological sort of the graph using Depth First Search (DFS).
Medium
Not Attempted
Video
24
24. Course Schedule II Introduction
Introduction to solving the Course Schedule II problem using Topological Sort.
Easy
Not Attempted
Video
25
25. Course Schedule II Code
Return the ordering of courses you should take to finish all courses. If it is impossible to finish all courses (cycle exists), return an empty array.
Medium
Not Attempted
Video
26
26. Largest Color Value In A Directed Graph
Conceptual breakdown of finding the largest color value of any valid path in a directed graph. A color value is the max frequency of any color on the path.
Hard
Not Attempted
Video
27
27. Largest Color Value In A Directed Graph | Code
Return the largest color value of any valid path in the given graph, or -1 if the graph contains a cycle.
Hard
Not Attempted
Video
28
28. Traversal on Grids
Introduction to visualizing and traversing 2D matrices / grids as graphs using DFS and BFS.
Easy
Not Attempted
Video
29
29. Flood Fill Introduction
Introduction to the Flood Fill algorithm. Used widely in applications like the 'paint bucket' tool in drawing software.
Easy
Not Attempted
Video
30
30. Flood Fill Code
Perform a flood fill on an image starting from a given pixel modifying it to the specified color. Returns the modified image grid.
Easy
Not Attempted
Video
31
31. Number of Islands
Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically.
Medium
Not Attempted
Video
32
32. Rotten Oranges | Conceptual
Introduction to the Rotten Oranges problem. Explains the concept of using Multi-source Breadth First Search (BFS) to track the simultaneous spread of rot from multiple starting points.
Medium
Not Attempted
Video
33
33. Rotten Oranges | Code
Implement the multi-source BFS algorithm. Return the minimum number of minutes that must elapse until no cell has a fresh orange. If impossible, return -1.
Medium
Not Attempted
Video
34
34. Geeks Village and Wells | Conceptual
Conceptual video discussing the logic of finding minimum distance from every house to the nearest well using a 2D matrix.
Medium
Not Attempted
Video
35
35. Geeks Village and Wells | Code
Return a 2D integer matrix of size n*m detailing the shortest path distance to fetch water from the nearest well (back and forth). Cells with 'N', 'W', and '.' have answer 0. Unreachable 'H' should be -1.
Medium
Not Attempted
Video
36
36. Number of Operations to Make Network Connected
Conceptual video discussing how to find the minimum number of operations required to make all computers in a network connected.
Medium
Not Attempted
Video
37
37. Number of Operations to Make Network Connected | Code
You are given an initial computer network connections. Return the minimum number of times you need to extract and place cables to make all computers connected. If it's not possible, return -1.
Medium
Not Attempted
Video
38
38. Shortest Path Algorithms
An introduction to shortest path algorithms in graphs, establishing the foundation before diving into Dijkstra's Algorithm.
Easy
Not Attempted
Video
39
39. Snakes and Ladders | Conceptual
Conceptual explanation of modeling the classic Snakes and Ladders board game as a Graph traversal problem.
Medium
Not Attempted
Video
40
40. Snakes and Ladders | Code
Return the least number of moves required to reach the square n^2 on a snakes and ladders board. If it is not possible, return -1.
Medium
Not Attempted
Video
41
41. Dijkstra Algo Intuition and Idea
Conceptual introduction to Dijkstra's Algorithm for finding single-source shortest paths in weighted graphs with non-negative edge weights.
Medium
Not Attempted
Video
42
42. Dijkstra Analysis and Examples
Conceptual video focused on analyzing how Dijkstra's Algorithm works on examples and why it is correct for non-negative weighted graphs.
Medium
Not Attempted
Video
43
43. Dijkstra Code
Given a weighted graph with non-negative weights and a source vertex, return the shortest distance from the source to all vertices.
Medium
Not Attempted
44
44. Path With Minimum Effort
Conceptual introduction to solving the Path With Minimum Effort problem on a grid, where path cost is defined by the maximum absolute height difference along the path.
Medium
Not Attempted
Video
45
45. Path With Minimum Effort Code
Given a grid of heights, return the minimum effort required to travel from the top-left cell to the bottom-right cell. The effort of a path is the maximum absolute difference between consecutive cells on that path.
Medium
Not Attempted
Video
46
46. Cheapest Flight within K Stops
Conceptual explanation for finding the cheapest flight path from a source to a destination with at most K stops.
Medium
Not Attempted
Video
47
47. Cheapest Flight within K Stops Code
Given n cities and flight prices, find the cheapest price from src to dst with up to k stops. Return -1 if no such route exists.
Medium
Not Attempted
Video
48
48. Bellman Ford Algo Part 1
Introduction to the Bellman-Ford Algorithm, detailing why it is necessary to handle graphs with negative weights where Dijkstra's algorithm fails.
Medium
Not Attempted
Video
49
49. Bellman Ford Algo Part 2
Extends the Bellman-Ford algorithm concept to detect negative weight cycles within a directed graph.
Medium
Not Attempted
Video
50
50. Bellman Ford Algo Code
Implementation of the Bellman-Ford algorithm to compute shortest paths from a source node, and return [-1] if a negative weight cycle is detected.
Medium
Not Attempted
Video
51
51. Floyd Warshall Algorithm
Conceptual introduction to the Floyd-Warshall Algorithm for finding all-pairs shortest paths in a directed weighted graph. Discusses how it handles negative weights but no negative cycles.
Medium
Not Attempted
Video
52
52. Floyd Warshall Algorithm Code
Implement the Floyd-Warshall algorithm to solve the all-pairs shortest path problem. Update the input adjacency matrix with shortest path distances.
Medium
Not Attempted
Video
53
53. Disjoint Union Set Introduction
Quick intro to the Disjoint Set Union (DSU) data structure, vital for dynamic connectivity, minimum spanning trees, and group relationships.
Easy
Not Attempted
Video
54
54. DSU Union and Find methods
Detailed exploration of the naive Union and Find operations to merge graph components and resolve group parents.
Easy
Not Attempted
Video
55
55. DSU Optimization techniques
Introduction to crucial optimizations for Disjoint Set Union: Path Compression and Union by Rank/Size, bringing time complexity to near constant time.
Medium
Not Attempted
Video