Easy to understand C++ Solution | Clear | Concise
IntuitionWe need to maximise height of each block such that the height difference between any two blocks is not greater than one and each water block has height
# Intuition
We need to maximise height of each block such that the height difference between any two blocks is not greater than one and each water block has height 0.
For every water block all its adjacent land block can have height at max 1. The next adjacent to these land block can have height 2 and so on...

# Approach
Use multisource BFS

# Complexity
- Time complexity:
O(n*m) - where n*m is the dimension of matrix.

Each cell in the matrix is visited exactly once. Hence the overall complexity is n*m.

- Space complexity:
O(n*m) - to store the answer array.

# Code
```cpp []
class Solution {
public:
    int n, m;
    vector<vector<int>> highestPeak(vector<vector<int>>& w) {
        n = w.size(), m = w[0].size();
        vector<vector<int>> ans(n, vector<int>(m, -1));

        vector<pair<int, int>> direction = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

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

        while (!q.empty()) {
            pair<int, int> cur = q.front();
            q.pop();

            for (auto dir: direction) {
                int i = cur.first + dir.first;
                int j = cur.second + dir.second;
                if (i >= 0 && i < n && j >= 0 && j < m && ans[i][j] == -1) {
                    ans[i][j] = ans[cur.first][cur.second] + 1;
                    q.push({i, j});
                }
            }
        }
        return ans;
    }
};
```
['Breadth-First Search', 'Matrix', 'C++']