@@ -0,0 +1,1518 @@
+%22%22%22%0D%0AIn a given grid, each cell can have one of three values:%0D%0A%0D%0Athe value 0 representing an empty cell;%0D%0Athe value 1 representing a fresh orange;%0D%0Athe value 2 representing a rotten orange.%0D%0AEvery minute, any fresh orange that is adjacent (4-directionally) to a rotten orange becomes rotten.%0D%0A%0D%0AReturn the minimum number of minutes that must elapse until no cell has a fresh orange.  If this is impossible, return -1 instead.%0D%0A%22%22%22%0D%0Aclass Solution:%0D%0A    def orangesRotting(self, grid: List%5BList%5Bint%5D%5D) -%3E int:%0D%0A        counter = -1%0D%0A        lenX, lenY = len(grid), len(grid%5B0%5D)%0D%0A        rot = True%0D%0A        while rot:%0D%0A            print(grid, rot)%0D%0A            changed = False%0D%0A            for i in range(lenX):%0D%0A                for j in range(lenY):%0D%0A                    if grid%5Bi%5D%5Bj%5D == 2:%0D%0A                        changed = rotFreshNeighbours(i, j, grid) or changed%0D%0A            rot = changed%0D%0A            counter += 1%0D%0A        for i in range(lenX):%0D%0A            for j in range(lenY):%0D%0A                if grid%5Bi%5D%5Bj%5D == 1:%0D%0A                    return -1%0D%0A        return counter%0D%0A%0D%0A%0D%0Adef rotFreshNeighbours(x, y: int, grid: List%5BList%5Bint%5D%5D) -%3E bool:%0D%0A    rotted = False%0D%0A    neighbours = %5B%5Bx+1, y%5D, %5Bx-1, y%5D, %5Bx, y+1%5D, %5Bx, y-1%5D%5D%0D%0A    for coords in neighbours:%0D%0A        nX, nY = coords%0D%0A        if nX %3C 0 or nX %3E= len(grid):%0D%0A            continue%0D%0A        if nY %3C 0 or nY %3E= len(grid%5B0%5D):%0D%0A            continue%0D%0A        if grid%5BnX%5D%5BnY%5D == 1:%0D%0A            rotted = True%0D%0A            grid%5BnX%5D%5BnY%5D = 2%0D%0A    return rotted%0D%0A

Add iterative approach that changes to quickly