`{"id":"bece3047-ffa7-4235-aaa1-579393cff1d6","name":"Edit Distance","description":"1. You are given two strings s1 and s2.\r\n2. You have to find the minimum number of operations needed to convert s1 to s2.\r\n Operations allowed are - \r\n Insert - You can insert any character in s1.\r\n Remove - You can remove any character in s1.\r\n Replace - You can replace any character in s1 with any other character.","inputFormat":"Two strings s1 and s2","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= length of s1,s2 &lt;= 100","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static int solution(String str1, String str2) {\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString s1 = scn.next();\r\n\t\tString s2 = scn.next();\r\n\t\tSystem.out.println(solution(s1,s2));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"pepperatcoding\r\npepcoding","sampleOutput":"5\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"a8d54641-2e64-4304-a0db-93bda87385fa","name":"Edit Distance","slug":"edit-distance","type":1}],"next":{"id":"7e842309-a8b6-4759-9c3c-e28e04fd9505","name":"Edit distance MCQ","type":0,"slug":"edit-distance-mcq"},"prev":{"id":"440c5f49-dc35-4579-9cb9-41dc71b576b7","name":"MINIMUM ASCII DELETE SUM FOR 2 STRINGS","type":3,"slug":"minimum-ascii-delete-sum-for-2-strings-9699"}}}`

# Edit Distance

1. You are given two strings s1 and s2. 2. You have to find the minimum number of operations needed to convert s1 to s2. Operations allowed are - Insert - You can insert any character in s1. Remove - You can remove any character in s1. Replace - You can replace any character in s1 with any other character.

`{"id":"bece3047-ffa7-4235-aaa1-579393cff1d6","name":"Edit Distance","description":"1. You are given two strings s1 and s2.\r\n2. You have to find the minimum number of operations needed to convert s1 to s2.\r\n Operations allowed are - \r\n Insert - You can insert any character in s1.\r\n Remove - You can remove any character in s1.\r\n Replace - You can replace any character in s1 with any other character.","inputFormat":"Two strings s1 and s2","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= length of s1,s2 &lt;= 100","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static int solution(String str1, String str2) {\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString s1 = scn.next();\r\n\t\tString s2 = scn.next();\r\n\t\tSystem.out.println(solution(s1,s2));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"pepperatcoding\r\npepcoding","sampleOutput":"5\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"a8d54641-2e64-4304-a0db-93bda87385fa","name":"Edit Distance","slug":"edit-distance","type":1}],"next":{"id":"7e842309-a8b6-4759-9c3c-e28e04fd9505","name":"Edit distance MCQ","type":0,"slug":"edit-distance-mcq"},"prev":{"id":"440c5f49-dc35-4579-9cb9-41dc71b576b7","name":"MINIMUM ASCII DELETE SUM FOR 2 STRINGS","type":3,"slug":"minimum-ascii-delete-sum-for-2-strings-9699"}}}`

Editor

# Edit Distance

hard

1. You are given two strings s1 and s2. 2. You have to find the minimum number of operations needed to convert s1 to s2. Operations allowed are - Insert - You can insert any character in s1. Remove - You can remove any character in s1. Replace - You can replace any character in s1 with any other character.

## Constraints

1 <= length of s1,s2 <= 100

## Format

### Input

Two strings s1 and s2

### Output

Check the sample output and question video.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}pepperatcoding pepcoding```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}5 ```

Discussions

Show Discussion

Related Resources