Motive Interview Question

Code the solution and then general discussion