The First Completely Painted Row or Column interview question is a grid simulation task. You are given an matrix and an array arr that specifies an order in which cells are "painted." You need to find the earliest index in arr such that either a full row or a full column in the matrix has been painted.
Companies like Google and Bloomberg ask this to test your ability to use Hash Tables for fast coordinate lookups. It evaluations if you can avoid redundant matrix scans () by maintaining counters for each row and column. It tests efficiency in Matrix interview patterns.
This problem follows the Coordinate Mapping and Frequency Counting pattern.
(row, col) coordinates for every value in the matrix. This allows lookup of a value's position.rowCount of size and colCount of size .arr:
(r, c) from the map.rowCount[r] and colCount[c].rowCount[r] == n OR colCount[c] == m, the row/column is complete.arr.Matrix : [[1, 2], [3, 4]]. arr = [1, 4, 2, 3].
(0,0). row0=1, col0=1.(1,1). row1=1, col1=1.(0,1). row0=2. Row 0 has 2 columns, it is now full!
Result: Index 2.Always look for ways to store "aggregate" information like row/column sums or counts. This transforms a 2D grid check into a 1D array lookup, which is a common optimization in Hash Table interview patterns.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Flip Columns For Maximum Number of Equal Rows | Medium | Solve | |
| Lonely Pixel I | Medium | Solve | |
| Lonely Pixel II | Medium | Solve | |
| Sparse Matrix Multiplication | Medium | Solve | |
| Set Matrix Zeroes | Medium | Solve |