-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbiggest_square.py
More file actions
32 lines (24 loc) · 788 Bytes
/
biggest_square.py
File metadata and controls
32 lines (24 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def solution(board):
x, y = len(board[0]), len(board)
if not sum([sum(b) for b in board]):
return 0
largest = 1
for j in range(y):
for i in range(x):
if i and j and board[j][i]:
board[j][i] = min(board[j-1][i], board[j-1][i-1], board[j][i-1]) + 1
if board[j][i] > largest:
largest = board[j][i]
return largest**2
print(solution([[0,1,1,1],
[1,1,1,1],
[1,1,1,1],
[0,0,1,0]])) # 9
print(solution([[0,0,1,1],
[1,1,1,1]])) # 4
print(solution([[0, 0],
[0, 1]])) # 1
print(solution([[1,1,1,1],
[0,1,1,1],
[0,1,1,1]])) # 9
print(solution([[0], [1]])) # 1