Solutions for problem 1
Solution for problem 2