Ctrl K

Cover Free Cells With Stickers

Hard
You are given an m × n board board: 0 marks a free cell and 1 an occupied one. You have an unlimited supply of identical rectangular stickers, each tall cells high and wide cells wide. Stickers follow these rules: - each sticker lies entirely on the board, aligned to the cells; - stickers cannot be rotated; - a sticker must not cover any occupied cell; - stickers may overlap, and you may use as many as you like. Return True if you can place stickers so that every free cell is covered, and False otherwise.
Example 1
board=[[0, 0, 0], [0, 0, 0], [1, 0, 0]], tall=2, wide=2 → True

Three 2×2 stickers with top-left corners at cells (0, 0), (0, 1) and (1, 1) together cover every free cell and miss the occupied one in the bottom-left corner.

Example 2
board=[[0, 1, 0], [0, 0, 0]], tall=2, wide=2 → False

Every 2×2 sticker on this board touches the occupied cell in the middle of the top row, so no sticker fits, yet free cells remain.

Example 3
board=[[1, 1], [1, 1]], tall=3, wide=3 → True

There are no free cells to cover, so the answer is True even though the sticker does not fit on the board at all.

Constraints
  • m = len(board), n = len(board[i])
  • 1 ≤ m, n ≤ 10⁵
  • 1 ≤ m · n ≤ 2 · 10⁵
  • board[i][j] is 0 or 1
  • 1 ≤ tall, wide ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsRichest Plot Under the Cap HardThe Heaviest Reading Day HardRectangles With a Given Sum HardCutting a Berry Cake HardFriends in One Row Hard
loading Python…
Input
board=[[0, 0, 0], [0, 0, 0], [1, 0, 0]], tall=2, wide=2
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.