Close
Topic list
Minimum Number of Deletions and Insertions
MEDIUM
Dynamic Programming
Topics (Covered in this problem)
Problem solved
Skill meter
Dynamic Programming
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Minimum Number of Deletions and Insertions

Contributed by
Medium
0/80
Share

## Problem Statement

#### You have to find the minimum number of operations required to convert string “str” into “ptr”.

##### For Example:
``````If str = “abcd”, ptr = “anc”
In one operation remove str[3], after this operation str becomes “abc”.
In the second operation remove str[1], after this operation str becomes “ac”.
In the third operation add ‘n’ in str[1], after this operation str becomes “anc”.

Hence, the output will be 3.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
abcd anc
aa aaa
``````
##### Sample output 1 :
``````3
1
``````
##### Explanation For Sample Output 1:
``````For the first test case,
str = “abcd”, ptr = “anc”

In one operation remove str[3], after this operation str becomes “abc”.
In the second operation remove str[1], after this operation str becomes “ac”.
In the third operation add ‘n’ in str[1], after this operation str becomes “anc”.

Hence, the output will be 3.

For the second test case,
str = “aaa”, ptr = “aa”

In one operation remove str[2], after this operation str becomes “aa”.

Hence, the output will be 1.
``````
##### Sample Input 2 :
``````2
cue dgo
edl xcqja
``````
##### Sample output 2 :
``````6
8
``````
Auto
Console