Ramp Interview Question

it was a bfs question