Solve without using reverse()