3
vector<vector<int>> highestPeak(vector<vector<int>> &isWater) {4
int r = isWater.size();5
int c = isWater[0].size();6
queue<pair<int, int>> curr;8
for (int i = 0; i < r; i++) {9
for (int j = 0; j < c; j++) {10
// set the land cell to -1 (not visited)11
if (isWater[i][j] == 0) {14
// set the water cell to zero and to queue23
while (!curr.empty()) {24
int len = curr.size();26
for (int k = 0; k < len; k++) {27
// for each cell check its 4 boundary cells28
// if it is not visited, increase its hill by 129
pair<int, int> fnt = curr.front();31
int i = fnt.first, j = fnt.second;34
if (i > 0 && isWater[i - 1][j] == -1) {35
isWater[i - 1][j] = hill + 1;36
curr.push({i - 1, j});39
if ((i < r - 1) && (isWater[i + 1][j] == -1)) {40
isWater[i + 1][j] = hill + 1;41
curr.push({i + 1, j});44
if (j > 0 && (isWater[i][j - 1] == -1)) {45
isWater[i][j - 1] = hill + 1;46
curr.push({i, j - 1});49
if ((j < c - 1) && (isWater[i][j + 1] == -1)) {50
isWater[i][j + 1] = hill + 1;51
curr.push({i, j + 1});55
// after 1 complete round increase the height of the hill