Initialize a queue to store the coordinates of water cells.
Initialize a matrix to store the heights, with the same dimensions as isWater.
Iterate over the isWater matrix to find all water cells and set their height to 0 in the height matrix and add them to the queue.
Perform BFS:
a. Dequeue a cell from the queue.
b. Check its four adjacent cells (up, down, left, right).
c. If an adjacent cell is land and has not been visited (height is not set), set its height to the current cell's height + 1.
d. Add the adjacent cell to the queue.