Uber Interview Question

Solve this coding problem within 45 minutes for round 1