Simple java solution || BFS traversal || daily question 22/01/2025
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```java []
class Solution {
    public int[][] highestPeak(int[][] isWater) 
    {
        Queue<int[]>q=new LinkedList<>();

        boolean visit[][]=new boolean[isWater.length][isWater[0].length];
        for(int i=0;i<isWater.length;i++)
        {
            for(int j=0;j<isWater[0].length;j++)
            {
                if(isWater[i][j]==1)
                {
                    q.add(new int[]{i,j});
                    isWater[i][j]=0;
                    visit[i][j]=true;
                }
            }
        }
        int dx[]={1,0,0,-1};
        int dy[]={0,1,-1,0};

        while(q.isEmpty()==false)
        {
            int temp[]=q.poll();
            int i=temp[0];
            int j=temp[1];

            for(int x=0;x<4;x++)
            {
                int nr=i+dx[x];
                int nc=j+dy[x];
                if(nr>=0&&nr<isWater.length&&nc>=0&&nc<isWater[0].length&&visit[nr][nc]==false)
                {
                    isWater[nr][nc]=isWater[i][j]+1;
                    q.add(new int[]{nr,nc});
                    visit[nr][nc]=true;
                }
            }
        }
        return isWater;
        
    }
}

```
['Breadth-First Search', 'Queue', 'Matrix', 'Java']