Java BFS
\n\n# Code\n\nclass Solution {\n    public int[][] highestPeak(int[][] isWater) {\n    int[][] result = new int[isWater.length][isWater[0].length];\n\n    Queue
\n\n# Code\n```\nclass Solution {\n    public int[][] highestPeak(int[][] isWater) {\n    int[][] result = new int[isWater.length][isWater[0].length];\n\n    Queue<int[]> cells = findWaterCells(isWater, result);\n    return bfs(cells, result);\n  }\n\n  private Queue<int[]> findWaterCells(int[][] isWater, int[][] result) {\n    Queue<int[]> cells = new LinkedList<>();\n    for (int row = 0; row < isWater.length; ++row) {\n      for (int column = 0; column < isWater[0].length; ++column) {\n        if (isWater[row][column] == 1)\n          cells.offer(new int[]{row, column});\n        else\n          result[row][column] = -1;\n      }\n    }\n    return cells;\n  }\n\n  private int[][] bfs(Queue<int[]> cells, int[][] result) {\n    int[][] directions = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n    while (!cells.isEmpty()) {\n      int[] cell = cells.poll();\n      int row = cell[0], column = cell[1];\n\n      for (int[] direction : directions) {\n        int newRow = row + direction[0], newColumn = column + direction[1];\n        if (newRow < 0 || newRow >= result.length\n          || newColumn < 0 || newColumn >= result[0].length\n          || result[newRow][newColumn] != -1)\n          continue;\n\n        result[newRow][newColumn] = result[row][column] + 1;\n        cells.offer(new int[]{newRow, newColumn});\n      }\n    }\n    return result;\n  }\n}\n```
['Java']