Implement recursive algorithm  for problem solv