2
def orangesRotting(self, grid: List[List[int]]) -> int:7
que = collections.deque()8
for i in range(len(grid)):9
for j in range(len(grid[0])):16
# This other while loop is to make sure that we traverse from all the rotten oranges in one turn.22
and c + Cols < len(grid[0])23
and grid[r][c + Cols] == 127
que.append((r, c + Cols))32
and r + Rows < len(grid)33
and grid[r + Rows][c] == 137
que.append((r + Rows, c))39
if either left or right or both is incremented it means that we have moved in either direction,40
and then this will be counted as a turn(or minute as per the problem description.).43
if left is not 0 or right is not 0:48
This is required to terminate the loop and prevent infinite loop.49
This only appends a None if there is still some values in the que,50
else we have completed our traversal and we can stop going any futher.56
for i in range(len(grid)):57
for j in range(len(grid[0])):