Go Solution with Detailed Explanation
For more golang solution, please check: https://github.com/yinfirefire/LeetCode-GoSol\ngo\nfunc numMovesStonesII(stones []int) []int {\n\tsort.Ints(stones)\n\t/
For more golang solution, please check: https://github.com/yinfirefire/LeetCode-GoSol\n```go\nfunc numMovesStonesII(stones []int) []int {\n\tsort.Ints(stones)\n\t// Upper bound:\n\t// 1, move the first stone A[0] to A[n-1]-n+1\n\t// the total number between new left bound and A[1] is the steps to take\n\t// A[n-1]-n+1-A[1]+1\n\t// 2, or move the last stone A[n-1] to A[0]+n-1\n\t// the total number between new right bound and A[n-2] is the steps to take\n\t// A[n-2]-(A[0]+n-1)+1\n\t//\n\t// Lower bound:\n\t// Sliding window size of len(stones), find vacancy in the current window, and the number of vacancy is the number\n\t// of steps\n\t// Edge Case: A[j]-A[i]==n-2 && j-i+1==n-1\n\t// e.g. 1,2,3,4,10: we need to move 1 to 6, then 10 to 5\n\tn := len(stones)\n\ti := 0\n\tmin := float64(n)\n\tmax := 0\n\tif stones[n-1]-n+1-stones[1]+1 < stones[n-2]-stones[0]-n+2 {\n\t\tmax = stones[n-2]-stones[0]-n+2\n\t}else{\n\t\tmax = stones[n-1]-stones[1]-n+2\n\t}\n\tfor j:=0; j<n; j++{\n\t\tfor stones[j]-stones[i]>=n{\n\t\t\ti++\n\t\t}\n\t\tif stones[j]-stones[i]==n-2&&j-i==n-2{\n\t\t\tmin = math.Min(min, float64(2))\n\t\t}else{\n\t\t\tmin = math.Min(min, float64(n-(j-i+1)))\n\t\t}\n\t}\n\treturn []int{int(min), max}\n}\n```
[]