String problem (Medium)

We are given two strings A and B consisting of lowercase English alphabet. We have to convert string B to string A using minimum number of operations. The only allowed operation is - we can choose any character from string B and put it to the start of string B itself. We have to report the minimum number of operations required to convert string B to string A or say that it is impossible to do so.
Example - Input - string A =“abcd”, string B=“bdac”
Output - 3
Explanation -string B can be converted to string A using transformations shown below-
“bdac” => “cbda” => “bcda” => “abcd”.
Please explain You approach in detail.

1 Like

The solution is available here.

1 Like

Thanks for your effort !