This site requires JavaScript.
It looks like you have disabled JavaScript in your browser or are using a browser that does not support JavaScript.
Please enable it or try another browser.

Ad Blocker Detected

You must disable your ad-blocking software for our web site in your browser to use this site.
You don't have to turn off the ad blocker entirely; just disable ad blocking for codestepbystep.com, then refresh this page to continue.

It is easy to disable a tool like AdBlock for just one site while leaving it enabled for other sites.
Just click the "stop sign" icon in the top-right of your browser, then un-check the "Enabled for this site" checkbox.
If your UI doesn't match the screenshot below, you may want to Google for how to add a "whitelisted domain" to your ad blocker to allow ads from codestepbystep.com to be shown.

Thank you for your understanding and helping us to keep this service free of cost for all students to use.

Note: If you are seeing this message but aren't running an ad blocker or have disabled your ad blocker:

Try clearing your browser history and refreshing the page.

Make sure you don't have any other ad-blocking software running outside of your browser, such as a HOSTS file or proxy.

If you are using a school computer network:
Many high schools have "proxy" software that blocks ads at the entire school level.
Your school's system administrator may need to add an exception for codestepbystep.com to allow these ads to get through.
You may need to copy/paste this information to your school's network administrator so that he/she can make appropriate changes to your network settings.

If you have questions or need any other assistance,
please Contact Us.

editDistance

Write a recursive function named editDistance that accepts string parameters s1 and s2 and returns the "edit distance" between the two strings as an integer.
Edit distance (also called Levenshtein distance) is defined as the minimum number of "changes" required to get from s1 to s2 or vice versa.
A "change" can be defined as
a) inserting a character,
b) deleting a character, or
c) changing a character to a different character.

Call

Value Returned

editDistance("driving", "diving")

1

editDistance("debate", "irate")

3

editDistance("football", "cookies")

6

Constraints:
Your solution must obey the following constraints:

Your solution must not use any loops it must be recursive.

Strings have member functions named indexOf, but you should not call them, because they allow you to get around using recursion.
Similarly, the replace and replaceAll members are forbidden.

Do not construct any data structures (no array, list, set, map, etc.), and do not declare any global variables.
You are allowed to define other "helper" functions if you like.

Type your Kotlin solution code here:

Spaces
Indent
Tabs

Sound F/X
Highlighting

This is a function exercise.
Write a Kotlin function as described.
Do not write a complete program; just the function(s) above.

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please