-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Labels
Description
LeetCode Username
sampleaccountpage
Problem Number, Title, and Link
https://leetcode.com/problems/stamping-the-grid/description/
Bug Category
Problem hints
Bug Description
The hints are incorrect and an implementation based on them would fail an existing test case.
Language Used for Code
None
Code used for Submit/Run operation
"""
hint: We can check if every empty cell is a part of a consecutive row of empty cells that has a width of at least stampWidth as well as a consecutive column of empty cells that has a height of at least stampHeight.
for each row:
find adjacent obstable and check there's a gap of at least stampWidth
transpose and check for stampHeight
[
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,1,0,0],
[0,0,0,0,1],
[0,0,0,1,1]
]
"""
class Solution:
def possibleToStamp(self, grid: List[List[int]], stampHeight: int, stampWidth: int) -> bool:
def check_gaps(threshold):
for cur_row in grid:
def check_row(row):
last_obstacle = -maxsize
# row_len = 0
prev = 0
all_zero = True
for i, cell in enumerate(row):
# row_len += 1
if cell:
all_zero = False
if not prev and i - last_obstacle - 1 < threshold:
return False
last_obstacle = i
prev = cell
# print(row_len - last_obstacle - 1 >= threshold, row_len, last_obstacle)
row_len = i + 1
if all_zero and row_len < threshold:
# print(row, any(row row_len, threshold)
return False
return row_len - last_obstacle - 1 >= threshold or last_obstacle == row_len - 1
if not check_row(cur_row) or not check_row(reversed(cur_row)):
return False
return True
if not check_gaps(stampWidth):
return False
grid = list(zip(*grid))
return check_gaps(stampHeight)Expected behavior
It should pass for this test case instead of actually failing.
[
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,1,0,0],
[0,0,0,0,1],
[0,0,0,1,1]
]Screenshots
No response
Additional context
No response