675. Cut Off Trees for Golf Event
class Solution(object):
def cutOffTree(self, forest):
# add border 0 so we do not need to index-checks later on
forest.append([0] * len(forest[0]))
for row in forest:
row.append(0)
# find the trees:
trees = [(height, i, j) for i, row in enumerate(forest)
for j, height in enumerate(row) if height > 1]
# Can we reach all the trees? if not return -1 right away
queue = [(0, 0)]
reached = set() # all the i,j can be reached
for i, j in queue: