BFS with Queue
Intuition\n\nWe have to fill every cell starting from water. Sound like BFS problem to me!\n\n# Approach\n\n1. Collect all of the water cells to Q first. Mark t
# Intuition\n\nWe have to fill every cell starting from water. Sound like BFS problem to me!\n\n# Approach\n\n1. Collect all of the water cells to Q first. Mark them as 0 level. Mark other cells with `-1`, so they are not visited yet.\n2. Keep maxH, as max level of water.\n3. Pop coordinates from Q and check for neighbours and set them cur maxH. \n\n\n# Complexity\n- Time complexity:\n`O(rows * cols)`\n\n- Space complexity:\n`O(1)`\n\n# Code\n```\ntype Pair struct {r, c int}\n\nfunc highestPeak(isWater [][]int) [][]int {\n    rows, cols := len(isWater), len(isWater[0])\n\n    q := []Pair{}\n\n    // collect water first\n    for r := 0; r < rows; r++ {\n        for c := 0; c < cols; c++ {\n            if isWater[r][c] == 1 {\n                q = append(q, Pair{r, c})\n                isWater[r][c] = 0\n            } else {\n                isWater[r][c] = -1\n            }\n        }\n    }\n\n    inBounds := func(r, c int) bool {\n        return r >= 0 && r < rows && c >= 0 && c < cols\n    }\n\n    maxH := 1\n\n    checkNei := func(r, c int) bool {\n        if !inBounds(r, c) || isWater[r][c] != -1 {\n            return false\n        }\n        isWater[r][c] = maxH\n        return true\n    }\n\n    \n    for len(q) != 0 {\n        n := len(q)\n        for i := 0; i < n; i++ {\n            cur := q[0]\n            q = q[1:]\n\n            if checkNei(cur.r + 1, cur.c) {q = append(q, Pair{cur.r + 1, cur.c})}\n            if checkNei(cur.r - 1, cur.c) {q = append(q, Pair{cur.r - 1, cur.c})}\n            if checkNei(cur.r, cur.c + 1) {q = append(q, Pair{cur.r, cur.c + 1})}\n            if checkNei(cur.r, cur.c - 1) {q = append(q, Pair{cur.r, cur.c - 1})}\n        }\n        maxH += 1\n    }\n\n\n    return isWater\n}\n```
['Breadth-First Search', 'Queue', 'Go']