[JAVA] Clean & Concise Code Using Breadth First Search | O(N) Time | 100% Faster Solution
\nclass Solution {\n    public int[][] highestPeak(int[][] isWater) {\n        \n        int rowLength = isWater.length;\n        int colLength = isWater[0].len
```\nclass Solution {\n    public int[][] highestPeak(int[][] isWater) {\n        \n        int rowLength = isWater.length;\n        int colLength = isWater[0].length;\n        int[][] directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n        int[][] heights = new int[rowLength][colLength];\n        Queue<int[]> queue = new LinkedList <>();\n        \n        for (int row = 0; row < rowLength; row++) {\n            for (int col = 0; col < colLength; col++) {\n                if (isWater[row][col] == 1) {\n                    heights[row][col] = 0;\n                    queue.offer (new int[] {row, col});\n                }\n                else {\n                    heights[row][col] = -1;\n                }\n            }\n        }\n        \n        while (!queue.isEmpty ()) {\n            int[] mat = queue.poll ();\n            \n            for (int[] direction : directions) {\n                int row = mat[0] + direction[0];\n                int col = mat[1] + direction[1];\n                \n                if (row < 0 || row == rowLength || col < 0 || col == colLength || heights[row][col] != -1) {\n                    continue;\n                }\n                \n                heights[row][col] = heights[mat[0]][mat[1]] + 1;\n                queue.offer (new int[] {row, col});\n            }\n        }\n        \n        return heights;\n    }\n}\n```\n\nPlease help to **UPVOTE** if this post is useful for you.\nIf you have any questions, feel free to comment below.\n**HAPPY CODING :)\nLOVE CODING :)**
[]