LeetCode
Beautiful Arrangement II
Click
here
for an explanation.