Given a 2-D grid of '0' (passable) and '+' (impassable) cells, return the indices of all rows and columns that are completely passable (contain only '0's).
Return a list of two lists: the first containing the sorted indices of all completely passable rows, and the second containing the sorted indices of all completely passable columns.
Function Signature
def passable_rows_and_columns(grid: list[list[str]]) -> list[list[int]]:
Rules
-
Every cell is the one-character string
"0"
or
"+"
.
-
The grid is rectangular: every row has the same length, which may differ from the number of rows.
-
Both lists are sorted in ascending order. When no row (or no column) qualifies, its list is empty, and the result still contains both lists.
Constraints
-
1 <= grid.length <= 100
-
1 <= grid[0].length <= 100
-
grid[i][j]
is either
'0'
or
'+'
Examples
Input: grid = [["0","0","0"],["+","0","0"],["0","0","0"]]
Output: [[0,2],[1,2]]
Rows 0 and 2 contain only '0', while row 1 starts with '+'. Column 0 has a '+' in row 1, so only columns 1 and 2 are completely passable.
Input: grid = [["+","+"],["+","+"]]
Output: [[],[]]
Every cell is blocked, so no row or column is completely passable and both lists are empty.
Input: grid = [["0","+","0"],["0","0","0"]]
Output: [[1],[0,2]]
Row 0 has a '+' in column 1, so only row 1 qualifies. Columns 0 and 2 are '0' in both rows, while column 1 is blocked in row 0.