Very Simple and Begineer-Friendly ✨| BFS
IntuitionThe problem asks us to assign a height to every cell in a grid such that:
Water cells (where isWater[i][j] == 1) have a height of 0.
Land cells (where
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem asks us to assign a height to every cell in a grid such that:
1. Water cells (where `isWater[i][j] == 1`) have a height of 0.
2. Land cells (where `isWater[i][j] == 0`) have heights based on how far they are from the nearest water cell.

To solve this, we can imagine starting at all water cells and spreading outwards, assigning heights to neighboring cells as we move further away. This way, we process all cells efficiently without repeatedly recalculating distances.
# Approach
<!-- Describe your approach to solving the problem. -->
1. **Grid Setup:**

- Create a new grid `ans` to store the heights. Start by marking every cell as `-1` (unvisited).
- Add all water cells (with height 0) to a queue. This allows us to start the BFS (Breadth-First Search) from all water cells at once.
2. **Using BFS:**

- BFS ensures that we explore all nearby cells layer by layer. From each cell, we check its neighbors `(up, down, left, right)`.
- If a neighboring cell hasn't been visited (its height in `ans` is still `-1`), assign it a height that is one more than the current cell and add it to the queue.
3. **Repeat Until Done:**

- Keep processing cells in the queue until all reachable cells have been visited, and the heights are assigned.

# 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
```cpp []
class Solution {
public:
    vector<pair<int, int>> dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
    
    vector<vector<int>> highestPeak(vector<vector<int>>& isWater) {
        int m = isWater.size(), n = isWater[0].size();
        vector<vector<int>> ans(m, vector<int>(n, -1)); 
        queue<pair<int, int>> q;

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (isWater[i][j] == 1) {
                    ans[i][j] = 0;
                    q.push({i, j});
                }
            }
        }

        while (!q.empty()) {
            auto [x, y] = q.front();
            q.pop();
            for (auto d : dir) {
                int nx = x + d.first, ny = y + d.second;
                if (nx >= 0 && nx < m && ny >= 0 && ny < n && ans[nx][ny] == -1) {
                    ans[nx][ny] = ans[x][y] + 1;
                    q.push({nx, ny});
                }
            }
        }
        return ans;
    }
};

```
['Breadth-First Search', 'C++']