Crude and undecorated solution
This is a direct dump of my thinking process ...\n  To make many moves as possible, we form a "blob" of numbers and have the "blob" crawl to the other end. With
This is a direct dump of my thinking process ...\n*  To make many moves as possible, we form a "blob" of numbers and have the "blob" crawl to the other end. With  this approach the answer will be related to the total width of the gaps;\n    * However,  if both endpoints are "lonely" (meaning they have no neighbors), then we must sacrifice either endpoints\n    ```\n\t Initial:                  1 _ _ _ _ _ 100 ... 10000 _ _ _ _ _ _ _ _ _ _ _ 10100\n\t Move 1 to the middle:                 100 ... 10000 _ _ _ _ _ _ _ _ _ _ _ 10100\n\t Move 100 to 10001:                     101 ... 10001_ _ _ _ _ _ _ _ _ _ _ 10100\n\t Move 101 to 10002:                      102 ... 10002 _ _ _ _ _ _ _ _ _ _ 10100\n\t Move 102 to 10003:                       103 ... 10003_ _ _ _ _ _ _ _ _ _ 10100\n\t                                          ^^^^^^^^^^^^^\n\t                  This "blob" just keeps moving to the right at unit length at a time \n\t\t\t\t\t  and eating up whatever gets in the way\n\t                  However to form the "blob" either gap next to a "lonely" endpoint must be dropped\n\t```\n\t\n* To make as few moves as possible, we move a sliding window over the initial configuration of the stones. However, there will be an extra processing for the "lonely" endpoints: We must make one extra move so that we could move the lone endpoint, just like in the second example:\n    ```\n\tInitial:       3 4 5 6 _ _ _ 10\n\tMove 3 to 8:     4 5 6 _ 8 _ 10    <-- 10 is lonely 10 cannot be moved to 7 (it will still be endpoint if directly moved to 7)\n\tMove 10 to 7:    4 5 6 7 8\n\t```\n\tWe must do this exactly once whenever there is a "lonely" endpoint. (We do not need to do this twice when both endpoints are lonely)\n\n\n```\nclass Solution {\npublic:\n\tint GetGapCount(vector<int>& stones, int* total_gap_length, int* first_gap_len, int* last_gap_len) {\n\t\tif (stones.size() < 2) return 0;\n\t\tint ret = 0, tl = 0;\n\t\tint prev = stones[0];\n\t\tfor (int i=1; i<stones.size(); i++) {\n\t\t\tint x = stones[i];\n\t\t\tif (x != prev + 1) {\n\t\t\t\tret ++;\n\t\t\t\tint gap_len = (x - prev - 1);\n\t\t\t\ttl += gap_len;\n\t\t\t\tif (i == 1) *first_gap_len = gap_len;\n\t\t\t\tif (i == (stones.size()-1)) *last_gap_len = gap_len;\n\t\t\t}\n\t\t\tprev = x;\n\t\t}\n\t\t*total_gap_length = tl;\n\t\treturn ret;\n\t}\n\tvector<int> numMovesStonesII(vector<int>& stones) {\n\t\tconst int N = int(stones.size());\n\t\tsort(stones.begin(), stones.end());\n\n\t\tvector<int> ret = { 0, 0 };\n\t\tint total_gap_length = 0;\n\t\tint first_gap_len = 0;\n\t\tint last_gap_len = 0;\n\t\tint num_gaps = GetGapCount(stones, &total_gap_length, &first_gap_len, &last_gap_len);\n\t\t//printf("num_gaps=%d\\n", num_gaps);\n\n\t\tif (num_gaps == 0) { }\n\t\telse {\n\t\t\tint min_skips = 2147483647;\n\t\t\tint idx0 = 0, idx1 = 0;\n\t\t\twhile (idx1 < N) {\n\t\t\t\tint num_in_window = idx1 - idx0 + 1;\n\t\t\t\tint gap_len = N - num_in_window;\n\t\t\t\tint num_skips = gap_len;\n\t\t\t\tif (num_skips < min_skips) { min_skips = num_skips; }\n\n\t\t\t\tidx1 ++;\n\t\t\t\tif (idx1 < N) {\n\t\t\t\t\twhile (stones[idx1] - stones[idx0] > (N-1)) idx0 ++;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tret[0] = min_skips;\n\t\t\tret[1] = total_gap_length;\n\n\t\t\tif (num_gaps >= 2) {\n\t\t\t\tif (stones[1] > stones[0]+1 && stones[N-2] < stones[N-1]-1) {\n\t\t\t\t\tret[1] -= min(first_gap_len, last_gap_len);\n\t\t\t\t}\n\t\t\t} else if (num_gaps == 1) {\n\t\t\t\t//printf("first_gap_len = %d\\n", first_gap_len);\n\t\t\t\tif ((stones[1] > stones[0]+1 && first_gap_len > 1) || \n\t\t\t\t    (stones[N-2] < stones[N-1]-1 && last_gap_len > 1)) {\n\t\t\t\t\tret[0] += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n};\n\n\n```
[]