c++ with picture
the max move\n\nintuition we need the max move A[n-1]-A[0]-n+1\n\nuse the case 1 2 99 100\n\n\n\n\nbut the endpoint stone exist an hole,  if you move the endpoi
## the max move\n\n**intuition we need the max move** `A[n-1]-A[0]-n+1`\n\nuse the case `1 2 99 100`\n\n![image](https://assets.leetcode.com/users/xiongqiangcs/image_1557397438.png)\n\n\n**but the endpoint stone exist an hole**,  if you move the endpoint stone firstly, the hole will disappear\n\nuse the case `1 100 102 105 200`\n\n![image](https://assets.leetcode.com/users/xiongqiangcs/image_1557396468.png)\n\n\n* move the leftmost endpoint stone firstly, the left hole disappear, and the  move is `A[n-1]-A[1]-n+2`\n![image](https://assets.leetcode.com/users/xiongqiangcs/image_1557397242.png)\n\n* samely\uFF0Cmove the rightmost endpoint stone firstly,  the right hole disappear, and the max move is `A[n-2]-A[0]-n+2`\n![image](https://assets.leetcode.com/users/xiongqiangcs/image_1557397698.png)\n\n* last, the max move is `min(A[n-1]-A[1]-n+2, A[n-2]-A[0]-n+2)`\n\n### the min move\n\n![image](https://assets.leetcode.com/users/xiongqiangcs/image_1557475637.png)\n\n\n```\nvector<int> numMovesStonesII(vector<int>& A) {\n\tsort(A.begin(), A.end());\n\tint n = A.size(), low = n;\n\tfor (int i = 0, j = 0; j < n; ++ j) {\n\t\twhile (A[j]-A[i]+1 > n) ++ i;\n\t\tint already_store = (j-i+1);\n\t\tif (already_store == n - 1 &&  A[j] - A[i] + 1 == n-1) {\n\t\t\tlow = min(low, 2);\n\t\t} else {\n\t\t\tlow = min(low, n - already_store);\n\t\t}\n\t}\n\treturn  {low, max(A[n-1]-A[1]-n+2, A[n-2]-A[0]-n+2)};\n}\n```
[]