A visualization of the solution of this
LeetCode problem
.