Solves problem 4