author's 3rd solution
author's 2nd solution