Snyk Interview Question

How would you make the recursive algorithm faster?