[Go] Simple Heap Queue Solution
Code\ngolang []\nimport (\n    "container/heap"\n)\n\nfunc minimumTime(grid [][]int) int {\n    // Edge case\n    if grid[0][1] > 1 && grid[1][0] > 1 {\n       
# Code\n```golang []\nimport (\n    "container/heap"\n)\n\nfunc minimumTime(grid [][]int) int {\n    // Edge case\n    if grid[0][1] > 1 && grid[1][0] > 1 {\n        return -1\n    }\n    m, n := len(grid), len(grid[0])\n    h := &Heap{[3]int{0, 0, 0}}\n    grid[0][0] = -1\n    for {\n        v := heap.Pop(h).([3]int)\n        for _, d := range directions {\n            r, c := v[1] + d[0], v[2] + d[1]\n            if r < 0 || r >= m || c < 0 || c >= n || grid[r][c] == -1 {\n                // out of boundary, or already visted\n                continue\n            }\n            // maintain t (time to visit {r, c})\n            t := v[0] + 1\n            if grid[r][c] > t {\n                t = grid[r][c]\n                if (r + c) % 2 != t % 2 {\n                    t++\n                }\n            }\n            if r == m - 1 && c == n - 1 {\n                // Found the goal\n                return t\n            }\n            grid[r][c] = -1 // Mark the position as visited\n            heap.Push(h, [3]int{t, r, c})\n        }\n    }\n}\n\nvar directions = [4][2]int{\n    {0, 1},\n    {1, 0},\n    {0, -1},\n    {-1, 0},\n}\n\ntype Heap [][3]int\nfunc (h Heap) Len() int { return len(h) }\nfunc (h Heap) Less(i, j int) bool { return h[i][0] < h[j][0] }\nfunc (h Heap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }\nfunc (h *Heap) Push(v any) { *h = append(*h, v.([3]int)) }\nfunc (h *Heap) Pop() any {\n    n := len(*h) - 1\n    old := *h\n    v := old[n]\n    *h = old[:n]\n    return v\n}\n```
['Go']