queue (bfs)
Start with setting the height of water tiles.
Then use a queue to solve the next step (bfs).O(RC)Code

Start with setting the height of water tiles.
Then use a queue to solve the next step (bfs).

O(RC)

# Code
```cpp []
class Solution {

    bool IsValid(const vector<vector<int>>& pike, const int r, const int c) {
        return r < R && c < C && r >= 0 && c >= 0 && pike[r][c] < 0;
    }
    int R;
    int C;
    static constexpr int r_offset[4] = {-1, 1, 0, 0};
    static constexpr int c_offset[4] = {0, 0, -1, 1};

public:
    vector<vector<int>> highestPeak(vector<vector<int>>& isWater) {
        R = isWater.size();
        C = isWater[0].size();
        vector<vector<int>> pike(R, vector<int>(C, -1));

        queue<pair<int, int>> work;

        for (int r = 0; r < R; ++r) {
            for (int c = 0; c < C; ++c) {
                if (isWater[r][c]) {
                    pike[r][c] = 0;
                    work.push({r, c});
                }
            }
        }

        while (!work.empty()) {
            const auto& [r, c] = work.front();
            for (int i = 0; i < 4; ++i) {
                if (IsValid(pike, r + r_offset[i], c + c_offset[i])) {
                    pike[r + r_offset[i]][c + c_offset[i]] = pike[r][c] + 1;
                    work.push({r + r_offset[i], c + c_offset[i]});
                }
            }
            work.pop();
        }
        return pike;
    }
};
```
['C++']