Practice

Problem 10 of 10

Problem · Hard · 40 min

Fewest edits

  • Hard
  • Dynamic programming
  • Strings

You can change a word with three kinds of edits. Each edit counts as one step:

  • Insert one letter at any place.
  • Delete one letter from any place.
  • Replace one letter with another letter.

Write min_edits(a, b). It returns the smallest number of edits that turn the word a into the word b.

  • min_edits("cat", "cut") is 1: replace a with u.
  • min_edits("kitten", "sitting") is 3.
  • Either word can be empty.
  • Each word has at most 60 letters.

Examples

Call Result
min_edits('cat', 'cut') 1
min_edits('kitten', 'sitting') 3
min_edits('', 'abc') 3

Tasks

2 to do

  1. Task 1, not checked yet. Make min_edits pass the example tests.

  2. Task 2, not checked yet. Make min_edits pass the hidden tests.

Task 1 of 2

Make min_edits pass the example tests.

All tasks

main.py

Ctrl+Enter runs your code. Ctrl+Shift+Enter runs all the tests. Press Esc, then Tab, to leave the editor.

Output

Press Run to see your result

Your output shows here. Press Run to try your code.