Week 2: Problem 3 solution