[Accepted] Swift
\nclass Solution {\n    func numMovesStonesII(_ stones: [Int]) -> [Int] {\n\n        guard stones.count > 2 else { return [0, 0] }\n        \n        var st = s
```\nclass Solution {\n    func numMovesStonesII(_ stones: [Int]) -> [Int] {\n\n        guard stones.count > 2 else { return [0, 0] }\n        \n        var st = stones.sorted()\n\n        let ma = st[st.count - 1] - st[0] - min(st[1] - st[0], st[st.count - 1] - st[st.count - 2]) + 2 - st.count\n        \n        let mi: Int = {\n            var mi = Int.max\n            var l = 0\n            var r = 0\n\n            while r + 1 < st.count, st[r + 1] - st[l] < stones.count { r += 1 }\n\n            while r < st.count {\n                while st[r] - st[l] >= stones.count { l += 1 }\n\n                let innerfree = st[r] - st[l] - r + l\n                let outerfree = st.count - st[r] + st[l] - 1\n\n                if outerfree == 1, innerfree == 0 { mi = min(mi, 2) }\n                else { mi = min(mi, innerfree + outerfree) }\n                \n                r += 1\n            }\n\n            return mi\n        }()\n\n        return [mi, ma]\n    }\n}\n\n\n\n/*\n\nxx.........................x\n\nx..x.xxxx.xx....x\nx.xxxx.xx...xx\n\n*/\n```
['Swift']