Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
depth-first search solution in Clear category for Radiation Search by David_Jones
def checkio(matrix):
n, m = len(matrix), len(matrix[0])
cells = {(x,y) for x in range(n) for y in range(m)}
largest = [0, 0]
while cells:
(x,y) = cells.pop()
size = 1
kind = matrix[x][y]
stack = [(x,y)]
while stack:
(x,y) = stack.pop()
for (x,y) in ((x-1,y), (x+1,y), (x,y-1), (x,y+1)):
if (x,y) in cells and matrix[x][y] == kind:
size += 1
stack.append((x,y))
cells.remove((x,y))
if size > largest[0]:
largest = [size, kind]
return largest
June 13, 2019