Trains the technique from
LeetCode 1582Special Positions in a Binary MatrixThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 1
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
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
Both pallets sit in column 0, so each of them shares its column with the other and neither is isolated.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def count_isolated_pallets(rack: list[list[int]]) -> int:public int countIsolatedPallets(int[][] rack)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.