Grids
Collections of problems involving 2-dimensional arrays of data.
Dated Jul 20, 2024; last modified on Sat, 20 Jul 2024
Collections of problems involving 2-dimensional arrays of data.
| Random Link ¯\_(ツ)_/¯ | ||||||||||||||
| May 29, 2026 | » | Valid Sudoku
3 min; updated May 29, 2026
Determine if a \(9 \times 9\) Sudoku board is valid. A Sudoku board has nine \(3 \times 3\) sub-boxes. Validate the filled cells such that each row, column, and sub-box contain the digits \([1, …, 9]\) without repetition. I don’t think we can do better than validating all 9 rows, 9 columns, and 9
sub-boxes. There’s no repeated work that can be optimized. At its core, this
problem is about traversing the grid in different ways. There is room for
improvement in how we handle each check. From the | ||||||||||||
| Jul 21, 2024 | » | Shortest Path in a Grid w/ Obstacles Elimination
6 min; updated Jul 21, 2024
Shortest Path in a Grid with Obstacles Elimination - LeetCode.
ProblemYou are given an \(m \times n\) Return the minimum number of steps to walk from the upper left corner
\((0, 0)\) to the lower-right corner \((m-1, n-1)\) given that you
can eliminate at most \(k\) obstacles. If it is not possible to find
such a walk, return | ||||||||||||
| Jul 20, 2024 | » | Queen's Movements on a Chessboard w/ Obstacles
5 min; updated Jul 20, 2024
Queen's Attack II.
ProblemA queen is standing on an \(n \times n\) chess board. The chess board’s rows are numbered from \(1\) to \(n\), going from bottom to top. Its columns are numbered from \(1\) to \(n\), going from left to right. Each square is referenced by a tuple \((r, c)\), describing the row, \(r\), and column, \(c\), where the square is located. ... | ||||||||||||
| Jul 20, 2024 | » | Minimizing Bottom-Right Paths in a 2xN Grid
4 min; updated Jul 20, 2024
Grid Game - LeetCode.
ProblemYou are given a 0-indexed 2D array Both robots initially start at \((0, 0)\) and want to reach \((1, n-1)\). Each robot may only move to the right or down. ... | ||||||||||||
| Jul 31, 2022 | » | Unique Paths to the Bottom-Right Corner w/ Obstacles
2 min; updated Jul 31, 2022
ProblemStarting from the top-left corner, what is the number of possible unique paths to reach the bottom-right corner, if you can only move either down or right at any point in time, and the path cannot include any square that is an obstacle? SolutionThe addition of obstacles has these implications:
| ||||||||||||
| Jul 31, 2022 | » | Spanning 4-Directional Walks From Origin to Destination w/ Obstacles
3 min; updated Jul 31, 2022
ProblemGiven an \(M \times N\) integer array
Return the number of 4-directional walks from the starting square to the ending square, that walk over every non-obstacle square exactly once. ... | ||||||||||||
| Jul 30, 2022 | » | Unique Paths to the Bottom-Right Corner
5 min; updated Jul 30, 2022
ProblemStarting from the top-left corner, what is the number of possible unique paths to reach the bottom-right corner, if you can only move either down or right at any point in time? Dynamic Programming Solution for Moving Down/RightThe number of unique paths to
At any given time, we’re interested in two adjacent rows, so our space usage should be at most \(2n\). Furthermore, we do not back-track to the left, so if we update our values left-to-right, we can use \(n\) space because the current cell will have the value from what would have been in the previous row. ... |
Unintuitive to me that given a
char c, we needc - '0'to convert it into anint.Convert.ToInt32('4')gives us52, not4.