second solution for question 3