Golang | BFS
\ntype State struct {\n    r, c, l int\n}\n\nfunc nearestExit(maze [][]byte, entrance []int) int {\n    m, n := len(maze), len(maze[0])\n    q := []State{{entra
```\ntype State struct {\n    r, c, l int\n}\n\nfunc nearestExit(maze [][]byte, entrance []int) int {\n    m, n := len(maze), len(maze[0])\n    q := []State{{entrance[0], entrance[1], 0}}\n    v := make(map[State]struct{})\n    var state, vState State\n    var rr, cc int\n    d4 := [][]int{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}\n    \n    for len(q) > 0 {\n        state, q = q[0], q[1:]\n        \n        vState = State{state.r, state.c, 0}\n        if _, ok := v[vState]; ok {\n            continue\n        }\n        v[vState] = struct{}{}\n        \n        if (state.r == 0 || state.r == m-1 || state.c == 0 || state.c == n-1) && (state.r != entrance[0] || state.c != entrance[1]) {\n            return state.l\n        }\n        \n        for _, d := range d4 {\n            rr, cc = state.r + d[0], state.c + d[1]\n            if rr >= 0 && rr < m && cc >= 0 && cc < n && maze[rr][cc] == \'.\' {\n                q = append(q, State{rr, cc, state.l+1})\n            }\n        }\n        \n    }\n    \n    return -1\n}\n```
['Go']