[Help] Google kickstart round H problem D
I can not understand the solution quite well. Would someone kindly help me explain the solution please?