[C++] Multi-source BFS. Easy and well commented. 
IntuitionThe matrix has all water cells at height h=0, and any adjacent cell can only have their height as h+1. A BFS traversal from the water cells sounds like
# Intuition
The matrix has all water cells at height `h=0`, and any adjacent cell can only have their height as `h+1`. A BFS traversal from the water cells sounds like a good approach.

---
# Approach
This problem can be thought of as a multi-source BFS problem, where all water cells are the initial source points. BFS is ideal here coz it traverses the matrix layer by layer.

First, we traverse through the matrix and enqueue all the cells with water, and mark them as visited. Then a BFS to all their adjacent cells (north, south, east, west) to cover the whole matrix, marking heights of each cell. 

---
# Complexity
- Time complexity: O(n * m)
--> Each cell is processed once to be enqueued in the queue, and then again for the BFS traversal.

- Space complexity: O(n * m)
--> `vis` matrix to track all the visited cells.
--> `heights` matrix to store the resultant heights of the matrix.
---
# Code
```cpp []
class Solution {
public:
    vector<vector<int>> highestPeak(vector<vector<int>>& mat) {
        int n = mat.size(), m = mat[0].size();
        
        // To track whether a cell is visited
        vector<vector<bool>> vis(n, vector<bool>(m, false));
        
        // Queue to hold cells to be processed in BFS
        queue<pair<int, pair<int, int>>> q;
        
        // Initialize the queue with all obstacle cells (mat[i][j] == 1)
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (mat[i][j] == 1) {
                    q.push({0, {i, j}}); // Starting point for BFS (height 0 for obstacles)
                    vis[i][j] = true;    // Mark as visited
                }
            }
        }
        
        // Result matrix to store heights
        vector<vector<int>> heights(n, vector<int>(m, 0));
        
        // Direction arrays for up, down, left, right
        int dr[] = {0, 0, 1, -1};
        int dc[] = {1, -1, 0, 0};
        
        // BFS to propagate the minimum height from obstacles
        while (!q.empty()) {
            auto front = q.front();
            q.pop();
            
            int h = front.first; // Current height
            int r = front.second.first; // Row index
            int c = front.second.second; // Column index
            
            // Set the height for the current cell
            heights[r][c] = h;
            
            // Explore neighboring cells
            for (int i = 0; i < 4; i++) {
                int nr = r + dr[i];
                int nc = c + dc[i];
                
                // Skip invalid or visited cells
                if (nr < 0 || nr >= n || nc < 0 || nc >= m || vis[nr][nc]) {
                    continue;
                }
                
                // Enqueue the neighboring cell with height h+1
                q.push({h + 1, {nr, nc}});
                vis[nr][nc] = true; // Mark the neighbor as visited
            }
        }
        
        // Return the final heights grid
        return heights;
    }
};
```
['Array', 'Breadth-First Search', 'Queue', 'Matrix', 'C++']