Add a recursive solution to the problem, but this solution failed for a very large test case due to unknown reason.