The Stamping the Grid coding problem is a "Hard" difficulty matrix challenge. You are given a grid of 0s (empty) and 1s (occupied), along with a stamp of size . You can place the stamp on any area of the grid that contains only 0s. The goal is to determine if it's possible to cover all the 0s in the grid using any number of stamps. Stamps can overlap, but they cannot cover any 1s.
Asked by Rubrik, this problem tests a candidate's mastery of 2D data structures and Greedy interview pattern. It's a complex multi-step problem: first, you need to find all valid stamp positions, and second, you need to check if those stamps cover everything. It requires efficient range-sum or range-update techniques to avoid complexity.
The algorithm uses a Greedy approach with 2D Prefix Sums (or 2D Difference Arrays).
Imagine a 5x5 grid with a 1 at the center (2,2) and a stamp size 2x2.
Mastering 2D Prefix Sums is essential for Matrix interview pattern problems involving subgrids. It allows you to query the sum of any rectangle in time after pre-processing.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Count Submatrices With Equal Frequency of X and Y | Medium | Solve | |
| Count Submatrices with Top-Left Element and Sum Less Than k | Medium | Solve | |
| Find Valid Matrix Given Row and Column Sums | Medium | Solve | |
| Grid Game | Medium | Solve | |
| Increment Submatrices by One | Medium | Solve |