This problem is also known as the Levenshtein distance. It is possible to solve recursively but that is very inefficient. Here is how to do it with dynamic programming. My initial logic didn’t work with recurring characters. I’ve highlighted the fix in red.
Source for the above:
And here’s code for a variation with my current coding style tastes: