Recursive solution