Grandshake interview question

Not generalised based on the take home assignment