word and need to turn it into the string goal. In one operation you may do one of four things: add a letter to the front, add a letter to the back, delete the first letter or delete the last letter. Letters in the middle cannot be changed.
Return the smallest number of operations that makes word equal to goal.word="planet", goal="lane" → 2
Cut p off the front and t off the back, leaving lane. Two operations.
word="stone", goal="tonic" → 4
The shared piece is ton. Drop s from the front and e from the back, then append i and c: 4 operations.
word="abc", goal="xyz" → 6
No letters in common: remove all three and add three new ones, 6 operations.
word="planet", goal="lane"
2
Run checks the first 3 tests in your browser. Submit checks all 145 tests on the server, hidden ones included.