dsa2 min read
2D Dynamic Programming — Master Recap & Cheatsheet
Complete 2D DP cheatsheet: 7 patterns, key transitions, stock state machine, interval DP template, and problem index.
Read →
1575 articles
Complete 2D DP cheatsheet: 7 patterns, key transitions, stock state machine, interval DP template, and problem index.
Master BFS and DFS on graphs and grids: islands, flood fill, shortest paths, connected components, and multi-source BFS with 5-language implementations.
Count connected land components in a binary grid using DFS flood fill or BFS. Classic easy problem, foundation for all island variants.
Implement the flood fill algorithm (like paint bucket tool): replace all cells of the same color reachable from a starting cell.
Calculate the perimeter of an island in a binary grid. Each land cell contributes 4 edges minus 2 for each land neighbour.