Motive interview question

Code the solution and then general discussion