💡BFS | ✅ Graph | Clean Code | Java
IntuitionTreat all water cells (isWater[i][j] == 1) as sources with height 0.Use multi-source BFS to expand outward, assigning each land cell a height that is 1
# Intuition
Treat all water cells (isWater[i][j] == 1) as sources with height 0.

Use multi-source BFS to expand outward, assigning each land cell a height that is 1 more than its neighboring cell.

This ensures the height difference between adjacent cells is ≤ 1, while maximizing the overall height.


# Complexity
- Time complexity: O(m × n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(m × n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    class Cell {
        int first;
        int second;
        int depth;
        Cell(int first, int second, int depth) {
            this.first = first;
            this.second = second;
            this.depth = depth;  
        }
    }

    public int[][] highestPeak(int[][] isWater) {
        int n = isWater[0].length;
        int m = isWater.length;
        Queue<Cell> q = new LinkedList<>();
        int[][] distance = new int[m][n];

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (isWater[i][j] == 1) {
                    distance[i][j] = 0;
                    q.add(new Cell(i, j, 0));
                } else {
                    distance[i][j] = -1;
                }
            }
        }

        while (!q.isEmpty()) {
            Cell node = q.remove();
            int first = node.first;
            int second = node.second;
            int depth = node.depth;

            // Right
            if (second < n - 1 && distance[first][second + 1] == -1) {
                distance[first][second + 1] = depth + 1;
                q.add(new Cell(first, second + 1, depth + 1));
            }

            // Left
            if (second > 0 && distance[first][second - 1] == -1) {
                distance[first][second - 1] = depth + 1;
                q.add(new Cell(first, second - 1, depth + 1));
            }

            // Down
            if (first < m - 1 && distance[first + 1][second] == -1) {
                distance[first + 1][second] = depth + 1;
                q.add(new Cell(first + 1, second, depth + 1));
            }

            // Up
            if (first > 0 && distance[first - 1][second] == -1) {
                distance[first - 1][second] = depth + 1;
                q.add(new Cell(first - 1, second, depth + 1));
            }
        }

        return distance;
    }
}
```
['Breadth-First Search', 'Graph', 'Java']