✅BFS | Deque | Beats 80% 👀
IntuitionA BFS method visits all nodes in a grid at the same level, adds their unvisited neighbors to the queue, and assigns them a level of  {current level} +
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
A BFS method visits all nodes in a grid at the same level, adds their unvisited neighbors to the queue, and assigns them a level of  `{current level} + 1` . Then, it moves on to the next level.

I wrote this solution as a reminder to myself that there’s no need to import another package to use deque here, and it’s much faster to use deque than a list for representing a queue.

# Complexity
- Time complexity: $$O(m*n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(m*n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:
        m = len(isWater)
        n = len(isWater[0])
        to_check = deque()
        for i in range(m):
            for j in range(n):
                isWater[i][j] -= 1
                if isWater[i][j] == 0:
                    to_check.append((i,j))
        neighbors_map = [[1, 0], [-1, 0], [0, 1], [0, -1]]
        while to_check:
            i, j = to_check.popleft()
            for neighbor in neighbors_map:
                i_n = i + neighbor[0]
                j_n = j + neighbor[1]
                if (0 <= i_n < m) and (0 <= j_n < n):
                    if isWater[i_n][j_n] == -1:
                        isWater[i_n][j_n] = isWater[i][j] + 1
                        to_check.append((i_n, j_n))
        return isWater
                




        
```
['Breadth-First Search', 'Python3']