Added optimal solution for problem4.