- BFS, Graph, Graph Traversals, Mathematical, Matrix

Maximum height of an elevation possible such that adjacent matrix cells have a difference of at most height 1

#include using namespace std;  #define M 3#define N 3  void findHeightMatrixUtil(int mat[][N],                          int height[M][N]){        queue q;          int vis[M][N] = { 0 };          for (int i = 0; i < M; i++) {        for (int j = 0; j < N; j++) {            if (mat[i][j] == 1) {                q.push({ i, j });                height[i][j] = 0;                vis[i][j] = 1;            }        }    }          while (q.empty() == 0) {          pair k = q.front();        q.pop();                          int x = k.first, y = k.second;                                            if (x > 0 && vis[x – 1][y] == 0) {            height[x – 1][y] = height[x][y] + 1;            vis[x – 1][y] = 1;            q.push({ x – 1, y });        }          if (y > 0 && vis[x][y – 1] == 0) {            height[x][y – 1] = height[x][y] + 1;            vis[x][y – 1] = 1;            q.push({ x, y – 1 });        }          if (x < M - 1 && vis[x + 1][y] == 0) {            height[x + 1][y] = height[x][y] + 1;            vis[x + 1][y] = 1;            q.push({ x + 1, y });        }          if (y < N - 1 && vis[x][y + 1] == 0) {            height[x][y + 1] = height[x][y] + 1;            vis[x][y + 1] = 1;            q.push({ x, y + 1 });        }    }}  void findHeightMatrix(int mat[][N]){        int height[M][N];          findHeightMatrixUtil(mat, height);          for (int i = 0; i < M; i++) {        for (int j = 0; j < N; j++)            cout