Map of Highest Peak [C++]
IntuitionThe problem requires assigning the height of each land cell in such a way that the height difference between adjacent cells is minimized, and all water
# Intuition
The problem requires assigning the height of each land cell in such a way that the height difference between adjacent cells is minimized, and all water cells have a height of 0. This can be modeled as a multi-source shortest path problem where water cells are the sources.

# Approach
1. **Initialization**: Create a `heights` matrix initialized to -1 to represent unvisited cells. Push all water cells (with height 0) into a queue as the starting points for the breadth-first search (BFS).
2. **BFS Traversal**: Use BFS to propagate the height values outward from the water cells. For each cell, check its neighbors. If a neighbor hasn't been visited (height is -1), set its height to the current cell's height + 1 and add it to the queue.
3. **Direction Array**: Use a direction array to simplify traversal to adjacent cells.
4. **Termination**: The process continues until all reachable cells are visited and assigned heights.

# Complexity
- **Time complexity**: \(O(m \times n)\)
  - Each cell is visited once, and its neighbors are processed in constant time.
- **Space complexity**: \(O(m \times n)\)
  - Space is used for the `heights` matrix and the queue.

# Code
```cpp
class Solution {
public:
    vector<vector<int>> highestPeak(vector<vector<int>>& isWater) {
        int m = isWater.size();
        int n = isWater[0].size();
        vector<vector<int>> heights(m, vector<int>(n, -1));
        queue<pair<int, int>> q;
        vector<pair<int, int>> directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

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

        while (!q.empty()) {
            auto [x, y] = q.front();
            q.pop();
            for (auto [dx, dy] : directions) {
                int nx = x + dx;
                int ny = y + dy;
                if (nx >= 0 && nx < m && ny >= 0 && ny < n && heights[nx][ny] == -1) {
                    heights[nx][ny] = heights[x][y] + 1;
                    q.push({nx, ny});
                }
            }
        }

        return heights;
    }
};
```
['C++']