dsa1 min read
Shortest Path in Binary Matrix — BFS 8-Directional
Find shortest clear path from top-left to bottom-right in binary matrix using 8-directional BFS. Return path length or -1.
Read →
webcoderspeed.com
1276 articles
Find shortest clear path from top-left to bottom-right in binary matrix using 8-directional BFS. Return path length or -1.
Find the water cell farthest from any land. Multi-source BFS from all land cells gives each water cell its min distance to land.
Search for a word in a grid by moving to adjacent cells without reuse. DFS with backtracking: mark visited, recurse, unmark.
Count islands with distinct shapes. Encode each island's DFS traversal path as a string to capture shape, store in a set.
Count islands fully surrounded by water (no border touch). Flood-fill border land first, then count remaining connected land components.