Golang BFS Solution
Inspired by : https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/discuss/431431/Java-straightforward-BFS-solution\n\ngolang\nfun
Inspired by : https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/discuss/431431/Java-straightforward-BFS-solution\n\n```golang\nfunc minPushBox(grid [][]byte) int {\n\tmv := [5]int{0, 1, 0, -1, 0}\n\tres := math.MaxInt32\n\tm := len(grid)\n\tn := len(grid[0])\n\tqueue := make([]int, 0, m*n)\n\tmem := make(map[int]int)\n\ttarget, st, box := [2]int{}, [2]int{}, [2]int{}\n\tfor i := 0; i < m; i++ {\n\t\tfor j := 0; j < n; j++ {\n\t\t\tswitch grid[i][j] {\n\t\t\tcase \'B\':\n\t\t\t\tbox = [2]int{i, j}\n\t\t\tcase \'T\':\n\t\t\t\ttarget = [2]int{i, j}\n\t\t\tcase \'S\':\n\t\t\t\tst = [2]int{i, j}\n\t\t\t}\n\t\t}\n\t}\n\tstart := encode(box[0], box[1], st[0], st[1])\n\tqueue = append(queue, start)\n\tmem[start] = 0\n\tfor len(queue) > 0 {\n\t\tcur := queue[0]\n\t\tqueue = queue[1:]\n\t\tif mem[cur] > res {\n\t\t\tcontinue\n\t\t}\n\t\tpos := decode(cur)\n\t\tif pos[0] == target[0] && pos[1] == target[1] {\n\t\t\tif mem[cur] < res {\n\t\t\t\tres = mem[cur]\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tb := [2]int{pos[0], pos[1]}\n\t\ts := [2]int{pos[2], pos[3]}\n\t\tfor i := 0; i < 4; i++ {\n\t\t\tsx := s[0] + mv[i]\n\t\t\tsy := s[1] + mv[i+1]\n\t\t\tif sx >= 0 && sx < m && sy >= 0 && sy < n && grid[sx][sy] != \'#\' {\n\t\t\t\tif sx == b[0] && sy == b[1] {\n\t\t\t\t\t//if the store keeper can move to the box position, check if the box can move one step further\n\t\t\t\t\tnbx := b[0] + mv[i]\n\t\t\t\t\tnby := b[1] + mv[i+1]\n\t\t\t\t\tif nbx >= 0 && nby >= 0 && nbx < m && nby < n && grid[nbx][nby] != \'#\' {\n\t\t\t\t\t\tnewpos := encode(nbx, nby, sx, sy)\n\t\t\t\t\t\tif val, ok := mem[newpos]; ok && val <= mem[cur]+1 {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tqueue = append(queue, newpos)\n\t\t\t\t\t\tmem[newpos] = mem[cur] + 1\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t//the store keeper move to other position, the number of steps shall not change\n\t\t\t\t\tnewpos := encode(b[0], b[1], sx, sy)\n\t\t\t\t\tif val, ok := mem[newpos]; ok && val <= mem[cur] {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tmem[newpos] = mem[cur]\n\t\t\t\t\tqueue = append(queue, newpos)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif res == math.MaxInt32 {\n\t\treturn -1\n\t} else {\n\t\treturn res\n\t}\n}\n\nfunc encode(bx int, by int, sx int, sy int) int {\n\tres := bx<<24 | by<<16 | sx<<8 | sy\n\treturn res\n}\n\nfunc decode(state int) [4]int {\n\tres := [4]int{}\n\tres[0] = (state >> 24) & 0xff\n\tres[1] = (state >> 16) & 0xff\n\tres[2] = (state >> 8) & 0xff\n\tres[3] = (state) & 0xff\n\treturn res\n}\n```\n\nMy other solutions in Golang: https://github.com/yinfirefire/LeetCode-GoSol
[]