Graphs, BFS and DFS coding problems
Graph problems model grids, networks and dependencies. Practise BFS for shortest paths, DFS for components and cycles, and topological order for prerequisites.
45 problems: 20 easy, 24 medium, 1 hard. Free to read; a free account solves them and earns XP and Aura.
- Count Black CellsPractice · +10 XP · matrix, traversal, beginnereasy
- Count Connected NodesPractice · +10 XP · graphs, bfs, dfseasy
- Count Nodes at Depth KPractice · +10 XP · trees, bfs, dfseasy
- Count Nodes in ComponentPractice · +10 XP · graphs, bfs, dfseasy
- Count Tree EdgesPractice · +10 XP · graphs, trees, bfseasy
- Find Linked List TailPractice · +10 XP · linked structures, arrays, traversaleasy
- Find Path LengthPractice · +10 XP · linked structures, simulation, traversaleasy
- Graph Node CountPractice · +10 XP · graphs, bfs, dfseasy
- Graph Node Degree SumPractice · +10 XP · graphs, bfs, dfseasy
- Graph Node NeighborsPractice · +10 XP · graphs, adjacency list, bfseasy
- Graph Path CountPractice · +10 XP · graphs, bfs, pathseasy
- Matrix Anti-Diagonal SumPractice · +10 XP · matrix, traversaleasy
- Matrix Diagonal ElementsPractice · +10 XP · matrix, traversaleasy
- Matrix Element SumPractice · +10 XP · matrix, traversal, loopseasy
- Matrix Saddle PointsPractice · +10 XP · matrix, grid, traversaleasy
- Matrix Spiral PrintPractice · +10 XP · matrix, traversaleasy
- Node Visit OrderPractice · +10 XP · graphs, bfs, dfseasy
- Print Tree LevelsPractice · +10 XP · trees, traversals, bfseasy
- Sum of Matrix DiagonalsPractice · +10 XP · matrix, traversaleasy
- Sum of Subtree SizesPractice · +10 XP · trees, dfs, recursioneasy
- Array Linked List SimulationPractice · +20 XP · linked structures, simulation, cycle detectionmedium
- Can Reach All NodesPractice · +20 XP · graphs, bfs, dfsmedium
- Cycle Detection and RendezvousPractice · +20 XP · linked structures, cycle detection, two pointersmedium
- Earliest Topological SortPractice · +20 XP · graphs, topological sort, bfsmedium
- Find Bridges in a TreePractice · +20 XP · graphs, dfs, treesmedium
- Find Duplicate Cycle EntryPractice · +20 XP · linked structures, hash map, cycle detectionmedium
- Find First Duplicate Entry PointPractice · +20 XP · linked structures, cycle detection, two pointersmedium
- Find Longest Path to LeafPractice · +20 XP · trees, dfsmedium
- Find Minimum Depth Binary TreePractice · +20 XP · recursion, trees, bfsmedium
- Find the Largest Component SizePractice · +20 XP · graphs, bfs, connected componentsmedium
- Graph Path ReconstructionPractice · +20 XP · graphs, bfs, shortest pathsmedium
- Graph Reachability by Edge TypePractice · +20 XP · graphs, bfs, dfsmedium
- Lexicographically Smallest PathPractice · +20 XP · recursion, dynamic programming, graphsmedium
- Linked List Jump GamePractice · +20 XP · linked structures, cycle detection, graph traversalmedium
- Linked List Path SumPractice · +20 XP · linked structures, hash map, cycle detectionmedium
- Matrix Neighbors SumPractice · +20 XP · matrix, bfs, hash mapmedium
- Maximum Depth Sum of Unique PathsPractice · +20 XP · trees, bfs, prefix summedium
- Minimum Path Sum in GridPractice · +20 XP · matrix, dynamic programming, bfsmedium
- Node Reachability by Path LengthPractice · +20 XP · graphs, bfs, shortest pathsmedium
- Shortest Path to Target NodePractice · +20 XP · graphs, bfs, shortest pathmedium
- Tree Diameter and CenterPractice · +20 XP · trees, bfsmedium
- Tree Path CountPractice · +20 XP · trees, dfsmedium
- Tree Subtree SumsPractice · +20 XP · trees, dfs, hash mapmedium
- Unreachable Nodes in a DAGPractice · +20 XP · graphs, topological sort, bfsmedium
- Minimum Cost Path on a Grid with Custom Edge WeightsPractice · +30 XP · sorting, dijkstra, graphshard
Solve these free. Get paid in XP and Aura.
One tap with Google, no card. Every first accepted solve pays XP for the leaderboards and Aura for real goodies.
Other topics
Hash Map and Hashing101Arrays88Prefix Sums64SQL and Databases64Beginner Coding Problems60Greedy41Sliding Window39Dynamic Programming37Sorting36Math and Number Theory36Strings35Two Pointers35Stack29Binary Search25Simulation25Recursion22Linked List20Trees20Heap and Priority Queue18Matrix and Grid18Bit Manipulation18Queue and Deque16