(18ms) Two passages
ApproachTwo passagesComplexityCode
# Approach
Two passages
# Complexity
![image.png](https://assets.leetcode.com/users/images/85e9b6f2-038d-4ba2-b733-f656ac6d77fd_1737525726.0277228.png)
# Code
```kotlin []
class Solution {
    fun highestPeak(mat: Array<IntArray>): Array<IntArray> {
        val n = mat.size
        val m = mat[0].size
        val rez = Array(n) { IntArray(m,{2001}) }
        
        // Top to bottom passage
        for (i in 0 until n) {
            for (j in 0 until m) {
                if (mat[i][j] == 1) rez[i][j] = 0
                else {
                    if (i > 0) rez[i][j] = minOf(rez[i][j], rez[i - 1][j] + 1)
                    if (j > 0) rez[i][j] = minOf(rez[i][j], rez[i][j - 1] + 1)
                }
            }
        }
        // Passage from bottom to top
        for (i in n - 1 downTo 0) {
            for (j in m - 1 downTo 0) {
                if (i < n - 1) rez[i][j] = minOf(rez[i][j], rez[i + 1][j] + 1)
                if (j < m - 1) rez[i][j] = minOf(rez[i][j], rez[i][j + 1] + 1)
            }
        }
        return rez
    }
}
```
['Kotlin']