LeetCode
Moving Stones Until Consecutive II
Click
here
for an explanation.