# Find regions with most common region size in a given boolean matrix

#include using namespace std;#define ROW 4#define COL 5  int isSafe(int M[][COL], int row, int col,           bool visited[][COL]){    return (row >= 0) && (row < ROW) && (col >= 0)           && (col < COL)           && (M[row][col] && !visited[row][col]);}  void DFS(int M[][COL], int row, int col,         bool visited[][COL], int& count){            static int rowNbr[] = { -1, -1, -1, 0, 0, 1, 1, 1 };    static int colNbr[] = { -1, 0, 1, -1, 1, -1, 0, 1 };          visited[row][col] = true;          for (int k = 0; k < 8; ++k) {        if (isSafe(M, row + rowNbr[k], col + colNbr[k], visited)) {                          count++;            DFS(M, row + rowNbr[k], col + colNbr[k],                visited, count);        }    }}  void commonRegion(int M[][COL]){            bool visited[ROW][COL];    memset(visited, 0, sizeof(visited));          unordered_map um;              for (int i = 0; i < ROW; ++i) {        for (int j = 0; j < COL; ++j) {                                      if (M[i][j] && !visited[i][j]) {                                  int count = 1;                                  DFS(M, i, j, visited, count);                um[count].push_back({ i, j });            }        }    }          int mostCommonRegion = 0;              for (auto it = um.begin(); it != um.end(); it++) {        int x = it->second.size();        mostCommonRegion = max(mostCommonRegion, x);    }              for (auto it = um.begin(); it != um.end(); it++) {          int x = it->second.size();        if (mostCommonRegion == x) {                          for (int i = 0; i < it->second.size(); i++) {                int x = it->second[i][0];                int y = it->second[i][1];                cout