BFS python approach modified and returned isWater matrix
Intuition/ApproachIt's Just BFS no huge modifications needed, I chose to store the height in the actual queue so that I wouldn't have to keep track of the level
# Intuition/Approach
It's Just BFS no huge modifications needed, I chose to store the height in the actual queue so that I wouldn't have to keep track of the levels and do it in the loop but I guess that is an optimization you could do to avoid having the extra variable in the queue

# Complexity
- Time complexity:
O(M * N)

- Space complexity:
O(M * N) I actually return the isWater matrix so I don't use extra space for this but I still need the queue and visited set

# Code
```python3 []
class Solution:
    def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:
        from collections import deque
        q = deque()
        visited = set()
        valid_moves = [(0,1), (0, -1), (1, 0), (-1, 0)]
        for i in range(len(isWater)):
            for j in range(len(isWater[0])):
                if isWater[i][j] == 1:
                    q.append((i, j, 0))
                    visited.add((i, j))
                    isWater[i][j] = 0
        while q:
            # print("In here")
            val = q.popleft()
            i, j, height = val[0], val[1], val[2]
            # print("i ",i, "j", j, "height", height, "grid val", isWater[i][j])
            for valid_move in valid_moves:
                i_add, j_add = valid_move[0], valid_move[1]
                i_new = i + i_add
                j_new = j + j_add
                # print("Changing values new_i, new_j", i_new, j_new)

                if i_new >= 0 and i_new < len(isWater) and j_new >= 0 and j_new < len(isWater[0]) and (i_new,j_new) not in visited:
                    visited.add((i_new, j_new))
                    q.append((i_new, j_new, height + 1))
                    # print("Changing is Water: ", i_new, j_new)
                    isWater[i_new][j_new] = height + 1
        return isWater
                




```
['Python3']