I try to find the time complexity of this recursive function, how can I solve this?
lets assume the inputs are positive numbers, and valid steps is a unique list
ex:
validsteps = [1,2] distance = 3
validsteps = [1,2,3] distance = 4
'''C#
int countpaths(int[] validsteps, int distance)
{
if (distance == 0)
{
return 1;
}
int paths = 0;
foreach (int step in validsteps)
{
if (distance >= step)
{
paths += countpaths(validsteps, distance - step);
}
}
return paths;
}