Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion matrix/largest_square_area_in_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ def largest_square_area_in_matrix_bottom_up_space_optimization(
2
>>> largest_square_area_in_matrix_bottom_up_space_optimization(2, 2, [[0,0], [0,0]])
0
>>> largest_square_area_in_matrix_bottom_up_space_optimization(
... 3, 3, [[1, 1, 1], [1, 1, 1], [1, 1, 0]]
... )
2
>>> largest_square_area_in_matrix_bottom_up_space_optimization(
... 4,
... 5,
... [
... [1, 0, 1, 0, 0],
... [1, 0, 1, 1, 1],
... [1, 1, 1, 1, 1],
... [1, 0, 0, 1, 0],
... ],
... )
2
>>> largest_square_area_in_matrix_bottom_up_space_optimization(0, 0, [])
0
"""
current_row = [0] * (cols + 1)
next_row = [0] * (cols + 1)
Expand All @@ -176,7 +193,8 @@ def largest_square_area_in_matrix_bottom_up_space_optimization(
largest_square_area = max(current_row[col], largest_square_area)
else:
current_row[col] = 0
next_row = current_row
# Swap row buffers rather than aliasing `next_row = current_row`.
current_row, next_row = next_row, current_row

return largest_square_area

Expand Down
Loading