LeetCode 1091: Shortest Path in Binary Matrix
A clear explanation of finding the shortest path from top-left to bottom-right in a binary matrix using BFS.
100 notes
A clear explanation of finding the shortest path from top-left to bottom-right in a binary matrix using BFS.
A clear explanation of counting submatrices with a given sum using 2D prefix sums combined with the subarray sum equals k technique.
A clear explanation of finding the maximum number of rows that can be made all-equal by flipping columns, using row pattern normalization.
A clear explanation of coloring the border of a connected component in a grid using BFS.
A clear explanation of sorting matrix cells by Chebyshev distance from a given center cell using BFS.
A clear explanation of counting land cells unreachable from the grid border using BFS from boundary land cells.
A clear explanation of solving Delete Columns to Make Sorted by checking each column independently.
A clear explanation of computing the projection areas of stacked cubes from top, front, and side views.
Simulate virus containment by repeatedly quarantining the most dangerous infected region and spreading the remaining regions.
Find the largest connected island area in a binary grid using depth-first search.
A clear explanation of randomly flipping zero cells in a matrix without repetition using hash mapping and virtual swapping.
A clear explanation of finding the shortest rolling distance in a maze using Dijkstra’s algorithm.
A clear explanation of counting battleships in a board using one-pass observation without modifying the grid.
A clear explanation of Number of Islands II using Union-Find to dynamically merge connected land cells.
A clear explanation of Range Sum Query 2D - Immutable using a 2D prefix sum matrix for constant-time rectangle queries.
A clear explanation of computing the minimum initial health needed to survive a dungeon using reverse dynamic programming.
A clear guide to finding the minimum path sum in a grid using dynamic programming.
A clear guide to counting unique paths in a grid with obstacles using dynamic programming.
A clear guide to counting unique paths in a grid using dynamic programming.
A clear explanation of counting regions formed by slashes using union find over four triangles per cell.
A clear explanation of the Magic Squares In Grid problem using fixed-size subgrid validation.
A clear explanation of the Image Overlap problem using translation vectors and frequency counting.
A clear explanation of the Flipping an Image problem using row reversal, bit inversion, and an in-place two-pointer method.
A clear explanation of the Making A Large Island problem using connected component labeling and island size lookup.
A clear explanation of Snakes and Ladders using breadth-first search over board squares.
A clear explanation of computing the exposed surface area of stacked cubes by adding tower area and subtracting shared faces.
A clear explanation of generating grid coordinates in an outward clockwise spiral using simulation.
A clear explanation of counting how many pawns a rook can capture by scanning four directions on a chessboard.
A clear explanation of finding the minimum time for all oranges to rot using multi-source BFS.
A clear explanation of counting all paths from start to end that visit every non-obstacle square exactly once using backtracking.
A clear explanation of transposing a matrix by swapping row and column indices.
A clear explanation of finding the minimum moves to collect all keys in a grid using BFS with key bitmasks.
A clear explanation of maximizing a binary matrix score using greedy row and column flips.
A clear explanation of solving Knight Dialer using dynamic programming over the phone keypad graph.
A clear explanation of solving Shortest Bridge using DFS to mark one island and BFS to expand toward the other island.
A clear explanation of solving Minimum Falling Path Sum using dynamic programming over matrix rows.
A greedy solution for increasing building heights as much as possible while preserving every skyline view.
A clear explanation of validating whether a Tic-Tac-Toe board can occur in a legal game.
A clear explanation of transforming a binary board into a chessboard using feasibility checks and minimum row and column swaps.
A clear explanation of finding the minimum time to reach the bottom-right cell using a priority queue and minimax path reasoning.
A clear explanation of solving the 2 x 3 sliding puzzle using breadth-first search over board states.
A clear explanation of checking whether every top-left to bottom-right diagonal in a matrix has the same value.
A clear explanation of finding the largest plus sign in a mined grid using four directional dynamic programming scans.
A clear explanation of restoring a Candy Crush board to a stable state using repeated marking, crushing, and gravity simulation.
Count axis-aligned rectangles whose four corners are 1 using column-pair frequency counting.
Maximize cherries collected on a round trip by converting the problem into two simultaneous forward paths and solving with dynamic programming.
Recolor the connected component containing the starting pixel using depth-first search.
Count unique island shapes in a binary grid using DFS and relative coordinates.
A clear explanation of cutting trees in increasing height order using repeated BFS on a grid.
A clear explanation of averaging neighboring pixels in a matrix using direct simulation.
A clear explanation of formatting a binary tree into a 2D string matrix using tree height and recursive placement.
A design solution for a small Excel-like spreadsheet that supports set, get, and dynamic sum formulas.
A clear explanation of searching a row-sorted and column-sorted matrix using the top-right corner elimination method.
A clear explanation of Rotate Image using in-place matrix transpose and row reversal.
A clear math solution for counting the maximum values after repeated top-left matrix increment operations.
A clear explanation of Maximum Vacation Days using dynamic programming over weeks and cities.
A clear explanation of Reshape the Matrix using index mapping from the original matrix to the reshaped matrix.
A clear explanation of Longest Line of Consecutive One in Matrix using dynamic programming over four directions.
A clear explanation of computing the distance to the nearest zero in a binary matrix using multi-source BFS.
A clear explanation of counting black lonely pixels using row counts, column counts, and duplicate row patterns.
A clear explanation of counting black pixels that are alone in both their row and column.
A clear explanation of updating a Minesweeper board using DFS flood fill and adjacent mine counting.
A clear explanation of finding the shortest rolling-ball path to the hole using Dijkstra with lexicographic tie-breaking.
A clear explanation of returning matrix elements in diagonal zigzag order by grouping cells with the same row plus column index.
A clear explanation of deciding whether a rolling ball can stop at the destination using BFS or DFS over stopping cells.
A clear explanation of counting the perimeter of an island in a grid by adding land-cell edges and subtracting shared edges.
Build a quad tree from a binary square grid using recursive divide and conquer.
A clear explanation of checking whether rows and columns read the same using direct index comparison.
A clear explanation of finding cells that can flow to both oceans using reverse graph traversal from the borders.
A clear explanation of trapping rain water in a 2D elevation map using a min heap and boundary expansion.
A clear explanation of finding the kth smallest value in a row-sorted and column-sorted matrix using binary search on values.
A clear explanation of reducing a 2D rectangle problem to a 1D prefix-sum problem with binary search.
A clear explanation of finding the best bomb placement in a grid using cached row and column segment counts.
A clear explanation of implementing Snake Game with a deque for body order and a set for constant-time collision checks.
A clear explanation of Android Unlock Patterns using backtracking, a jump table, and symmetry optimization.
A clear explanation of Design Tic-Tac-Toe using row, column, and diagonal counters for constant-time winner checks.
A clear explanation of Longest Increasing Path in a Matrix using DFS with memoization.
A clear explanation of Shortest Distance from All Buildings using BFS from each building with distance and reach accumulation.
A clear explanation of Sparse Matrix Multiplication using non-zero entries to avoid wasted work.
A clear explanation of Range Sum Query 2D - Mutable using a 2D Fenwick Tree for efficient updates and rectangle sum queries.
A clear explanation of Smallest Rectangle Enclosing Black Pixels using binary search on rows and columns.
A median-based solution for minimizing total Manhattan distance in a grid.
An in-place matrix simulation for computing the next state of Conway's Game of Life using temporary encoded states.
A multi-source BFS solution for filling each empty room with its shortest distance to the nearest gate.
A clear explanation of finding the largest square of 1s in a binary matrix using dynamic programming.
A clear explanation of finding multiple words in a character board using a Trie and DFS backtracking.
A detailed guide to solving Maximal Rectangle by converting each matrix row into a histogram and applying a monotonic stack.
A detailed guide to solving Word Search with depth-first search and backtracking on a grid.
A clear explanation of counting connected groups of land cells in a grid using DFS or BFS.
Capture surrounded O regions by marking border-connected O cells first, then flipping the remaining O cells.
A clear guide to searching a sorted 2D matrix using binary search over a virtual one-dimensional array.
A clear guide to setting matrix rows and columns to zero in place using the first row and first column as markers.
A clear guide to generating an n x n matrix filled from 1 to n squared in spiral order.
A clear guide to reading a matrix in spiral order using shrinking boundaries.
A clear explanation of solving a Sudoku board using backtracking and constraint checking.
A clear explanation of checking whether a partially filled Sudoku board is valid using hash sets.
Select the k-th smallest element from a matrix whose rows and columns are sorted.
Search a matrix sorted by rows and columns using divide and conquer.
Search a matrix sorted by rows and columns using a monotone path from a corner.
Search a row-major sorted matrix by treating it as a virtual sorted array.