C++ | BFS | Beats 88%
IntuitionWe aim to maximize the height of the cells while ensuring the height difference between adjacent cells is at most 1. To achieve this, we start with the
# Intuition
We aim to maximize the height of the cells while ensuring the height difference between adjacent cells is at most 1. To achieve this, we start with the minimum height, then update all adjacent cells by assigning them a height of **minHeight + 1**.

# Approach 
A simple BFS traversal can solve this:  
1. Start with cells having water (height 0) and add them to a queue.  
2. For each cell, update all adjacent cells to **minHeight + 1** and add them to the queue for further processing.
3. Since we start with 0 (the minimum possible height), **minHeight** corresponds to the current height of the cell being processed.

# Complexity
- Time complexity: O(n*m) --> each cell is visited once

- Space complexity: o(n*m)

# Code
```cpp []
class Solution {
public:
    int dx[4]={0,0,1,-1};
    int dy[4]={1,-1,0,0};
    bool check(int u,int v,int n, int m,vector<vector<int>>&ans){
        if(u>=0&&u<n&&v>=0&&v<m&&ans[u][v]==-1)return true;
        return false;
    }
    vector<vector<int>> highestPeak(vector<vector<int>>& a) {
        int n=a.size();
        int m=a[0].size();

        vector<vector<int>>ans(n,vector<int>(m,-1));

        // mark height of water 0 & push into queue
        queue<pair<int,int>>q;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(a[i][j]==1){
                    q.push({i,j});
                    ans[i][j]=0;
                }
            }
        }

        // bfs traversal for marking height from min to max
        int ctr=0;
        while(!q.empty()){
            int size=q.size();
            ctr++;
            while(size--){
                int i=q.front().first;
                int j=q.front().second;
                q.pop();

                for(int k=0;k<4;k++){
                    int u=i+dx[k];
                    int v=j+dy[k];
                    if(check(u,v,n,m,ans)){
                        ans[u][v]=ctr;
                        q.push({u,v});
                    }
                }
            }
        }

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