Implement pathsToGoal, solution