Problem 1040 · Medium

Moving Stones Until Consecutive II

Sort the stones, then use a sliding window of span n for the fewest moves and the two outer gaps for the most.

Open the interactive visualisation