LeetCode
Flip Game II
Click
here
for an explanation.