String, DP. [GOOGLE INTERN] onsite
Anonymous User
970

You are given two strings A and B of same length comprising of same charachters in equal amount. You need to convert string A to B by performing following operations :

  1. You can use first charachter or last charachter remove from string.
  2. Insert the charachter choosen from start or end into the remaining string.
    Each operation cost 1. Find the minimum cost

Example
INPUT : A="edacb" , B="abcde"
OUTPUT : 3

Explanation
step1 . take last charachter 'b' and insert it between a and c :
edacb converted to edabc
step2 . take first charachter 'e' insert it to last
edabc converted to "dabce"
step3 . take first charachter 'd' and insert it between c and e
dabce converted to abcde
Solve it .

Comments (8)