Special Positions in a Binary Matrix
Real-world version: Isolated Pallets on the RackThe statement here is our own: the same inputs, outputs and technique.
A storage rack is laid out as a grid with m aisles and n columns. rack[i][j] is 1 when a pallet sits in the slot at aisle i, column j, and 0 when that slot is empty.
A pallet is isolated when no other pallet shares its aisle and no other pallet shares its column. Return how many isolated pallets the rack holds.
Examples
Example 1
- Input
- rack = [[1, 0, 0], [0, 0, 0], [0, 0, 1]]
- Output
- 2
The pallet at aisle 0, column 0 has its aisle and its column to itself, and so does the pallet at aisle 2, column 2, so both are isolated.
Example 2
- Input
- rack = [[1, 0, 0, 0], [0, 0, 1, 0]]
- Output
- 2
One pallet sits at aisle 0, column 0 and the other at aisle 1, column 2. Neither shares an aisle or a column with the other, so both are isolated.
Example 3
- Input
- rack = [[1, 0], [1, 0]]
- Output
- 0
Both pallets sit in column 0, so each of them shares its column with the other and neither is isolated.
Constraints
- m == rack.length
- n == rack[i].length
- 1 <= m, n <= 100
- rack[i][j] is either 0 or 1.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def count_isolated_pallets(rack: list[list[int]]) -> int:public int countIsolatedPallets(int[][] rack)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's