This site uses JavaScript for navigation, themes, and games like 2048. Please enable JavaScript in your browser settings, then reload the page.
60 problems. Click one to open the details.
0/60 solved
1.Graph Representation
Adjacency list vs matrix; when to use each.
2.BFS Traversal
Level-order walk from a source using a queue.
3.DFS Traversal
Depth-first walk using recursion or an explicit stack.
4.Number of Provinces
Count connected components in an undirected graph.
5.Flood Fill
Recolor a connected region of equal cells in a grid.
6.Rotten Oranges
Multi-source BFS: minutes until all oranges rot.
7.01 Matrix
Distance of each cell to the nearest 0 via multi-source BFS.
8.Surrounded Regions
Capture O regions fully enclosed by X; border-safe DFS first.
9.Number of Enclaves
Count land cells that cannot walk off the boundary.
10.Number of Islands
Count islands of 1s in a binary grid.
11.Number of Distinct Islands
Count unique island shapes via normalized path signatures.
12.Bipartite Graph — BFS
2-color the graph with BFS; odd cycle ⇒ not bipartite.
13.Bipartite Graph — DFS
Same 2-coloring check using DFS.
14.Detect Cycle in Undirected Graph — BFS
BFS with parent tracking; revisit non-parent ⇒ cycle.
15.Detect Cycle in Undirected Graph — DFS
DFS with parent; back-edge to visited non-parent ⇒ cycle.
16.Detect Cycle in Directed Graph — DFS
White/gray/black or recursion-stack mark for directed cycles.
17.Topological Sort — DFS
Finish-time order on a DAG via DFS.
18.Topological Sort — Kahn BFS
Peel indegree-0 nodes; Kahn's algorithm.
19.Course Schedule
Can finish all courses? Detect directed cycle / valid topo.
20.Course Schedule II
Return a valid course order or empty if impossible.
21.Eventual Safe States
Nodes that never reach a cycle; safe terminal components.
22.Shortest Path in Undirected Unit Graph
BFS distances from source when every edge weight is 1.
23.Shortest Path in DAG
Topo order then relax edges once for DAG shortest paths.
24.Dijkstra — Introduction
Greedy shortest paths for non-negative weights; why it fails with negatives.
25.Dijkstra — Implementation
Priority-queue Dijkstra; relax neighbors of the closest unsettled node.
26.Dijkstra — Set / PQ Variants
Set-based or lazy PQ Dijkstra; duplicate keys vs decrease-key.
27.Shortest Path in a Binary Maze
0/1 grid path length with 4-direction BFS.
28.Path With Minimum Effort
Minimize max absolute height diff along a path (Dijkstra on effort).
29.Cheapest Flights Within K Stops
Bounded stops: Bellman-Ford K+1 rounds or layered BFS.
30.Network Delay Time
Time for signal to reach all nodes = max Dijkstra distance.
31.Bellman-Ford Algorithm
Relax all edges |V|-1 times; detect negative cycles.
32.Floyd-Warshall Algorithm
All-pairs shortest paths via DP on intermediate nodes.
33.City With the Smallest Number of Neighbors
Within distance threshold, city with fewest reachable others.
34.Prim's Algorithm (MST)
Grow MST by adding the lightest edge out of the tree.
35.Kruskal's Algorithm (MST)
Sort edges; add if endpoints in different DSU components.
36.Disjoint Set Union (Union-Find)
Find with path compression; union by rank/size.
37.Number of Operations to Make Network Connected
Need n-1 cables; extras can reconnect components.
38.Most Stones Removed with Same Row or Column
Stones sharing row/col are connected; removable = n − components.
39.Accounts Merge (DSU)
Merge accounts that share an email via union-find.
40.Number of Islands II
Online land additions; maintain island count with DSU.
41.Making A Large Island
Flip one 0 to 1 to maximize resulting island size.
42.Bridges in Graph (Tarjan)
Discovery/low-link to find critical edges.
43.Articulation Points
Nodes whose removal increases component count.
44.Strongly Connected Components — Kosaraju
DFS order on G, then DFS on Gᵀ for SCCs.
45.Find if Path Exists in Graph
Reachability between source and destination.
46.Steps by Knight
Minimum knight moves on a board — BFS on chess graph.
47.Reorder Routes to City Zero
Count edges to reverse so every city reaches 0.
48.Largest Color Value in a Directed Graph
Topo DP counting max color frequency on any path.
49.Longest Cycle in a Graph
Each node outdegree ≤ 1; find longest cycle.
50.Swim in Rising Water
Min time t so a path exists with all heights ≤ t.
51.Min Cost to Connect All Points
MST on complete graph of Manhattan distances.
52.Word Ladder Length (BFS)
Shortest transformation sequence length via word graph BFS.
53.Alien Dictionary (Intro)
Build char graph from sorted words; topo order for the alphabet.
54.Critical Connections in a Network
LeetCode framing of bridges — edges not on any cycle.
55.Graph Coloring Ideas
Chromatic ideas, bipartite = 2-colorable, greedy coloring bounds.
56.Word Ladder I
Shortest word transformation length (BFS).
57.Alien Dictionary
Topo sort characters from sorted alien words.
58.Minimum Spanning Tree Weight
Return MST total weight (Prim/Kruskal).
59.Accounts Merge
Union emails; group accounts.
60.Bridges in Graph
Tarjan bridges / critical connections.