Map Syntax cpp

Can someone please explain this map Initialization?

map<char,int>row[9],col[9],block[9];

Here’s the code snippet.

int Solution::isValidSudoku(const vector &board) {
map<char,int>row[9],col[9],block[9];
char c;
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
c=board[i][j];
if((c!=’.’) && (0<row[i][c]++ || 0<col[j][c]++ ||0<block[i/3*3+j/3][c]++)){
return false;
}
}
}
return true;
}

The declaration(s):

    map<char,int>row[9],col[9],block[9];

can be broken down a little to make them (hopefully!) less confusing:

using CharToIntMap = map<char, int>;
CharToIntMap row[9];   // An array of 9 CharToIntMaps, called "row".
CharToIntMap col[9];   // An array of 9 CharToIntMaps, called "col".
CharToIntMap block[9]; // An array of 9 CharToIntMaps, called "block".
3 Likes

What is the meaning of creating array of map ?

Same meaning as creating an array of anything else :slight_smile:

4 Likes

Now I see, it was a meaningless question :sweat_smile:. I had never used array of map, so some doubt came in my mind when it will come in use.

1 Like

Thanks mate! :grin:

1 Like