Add recursive way to solve the algorithm