JavaScript Sliding Window
Maximum\nThe idea of getting the maximum is to use up all the empty slots available.\nAnd since left most item cannot be left most item again and same to right 
**Maximum**\nThe idea of getting the maximum is to use up all the empty slots available.\nAnd since left most item cannot be left most item again and same to right most item, we have to move left most item to the right of A[1], and right most item to the left of A[n-2].\nThus all the empty slots available is either A[n-1] - A[1] - 1 - (n-3) (start with moving left most item), or A[n-2] - A[0] - 1 - (n-3) (start with moving right most item), n-3 is the number of items that already there.\n\n**Minimum**\nThe idea of getting the minimum is to use as many items that we do not need to move as possible.\nWe have the sliding window [i,j], where window length(A[j]-A[i]) is smaller than the length of n, which means items within the window are deff within the consecutive list, so that they do not need to move.\nNow we just need to count the items outside the sliding window which need to be moved, which is n - (j - i + 1).\nThough we need to consider when the items within the window are already consecutive and we have one item left, it takes 2 moves to make all of them consecutive.\ne.g.\n2,3,4,8\n\n```\n/**\n * @param {number[]} stones\n * @return {number[]}\n */\nvar numMovesStonesII = function(stones) {\n    let min = +Infinity;\n    let n = stones.length;\n    stones.sort((a,b) => a-b);\n    let max = Math.max(\n        stones[n-2]-stones[0]-1-(n-3), \n        stones[n-1]-stones[1]-1-(n-3));\n    let i = 0;\n    for (let j = 0; j < n; j++) {\n        while (stones[j] - stones[i] >= n) i++;\n        if (j - i + 1 == n - 1 && stones[j] - stones[i] == n - 2)\n            min = Math.min(min, 2);\n        else\n            min = Math.min(min, n - (j - i + 1));\n    }\n    return [min,max];\n};\n```
[]