A more general solution for problem 11