Cruise interview question

Solve the live coding problem.