C
\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint cmp(const void* a, const void* b){\n    return *(int*)a - *(int*)b ;\
```\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint cmp(const void* a, const void* b){\n    return *(int*)a - *(int*)b ;\n}\nint* numMovesStonesII(int* stones, int stonesSize, int* returnSize){\n    int n = stonesSize ;\n    *returnSize = 2 ;\n    qsort(stones, n, sizeof(int), cmp) ;\n    int* ans = malloc(2 * sizeof(int)) ;\n    int upper , lower = n ;\n    upper = fmax(stones[n-1] - stones[1] + 1 - n + 1, stones[n-2] - stones[0] + 1 - n + 1) ;\n    int left = 0 ;\n    for(int right = 0; right < n; right++){\n        while(stones[right] - stones[left] + 1  > n)\n            left++ ;\n        \n        if( stones[right] - stones[left] + 1 == n-1 && right - left + 1 == n-1 )\n            lower = fmin(lower, 2) ;\n        else\n            lower = fmin(lower, n - (right - left + 1)) ;\n    }\n    ans[0] = lower ;\n    ans[1] = upper ;\n    return ans ;\n}\n```
[]