Given two strings A and B. Find the minimum number of steps required to transform string A into string B. The only allowed operation for the transformation is selecting a character from string A and inserting it in the beginning of string A.
Input: A = "abd" B = "bad" Output: 1 Explanation: The conversion can take place in 1 operation: Pick 'b' and place it at the front.
Input: A = "GeeksForGeeks" B = "ForGeeksGeeks" Output: 3 Explanation: The conversion can take place in 3 operations: Pick 'r' and place it at the front. A = "rGeeksFoGeeks" Pick 'o' and place it at the front. A = "orGeeksFGeeks" Pick 'F' and place it at the front. A = "ForGeeksGeeks"
You dont need to read input or print anything. Complete the function transform() which takes two strings A and B as input parameters and returns the minimum number of steps required to transform A into B. If transformation is not possible return -1.
Expected Time Complexity: O(N) where N is max(length of A, length of B)
Expected Auxiliary Space: O(1)
1<= A.length(), B.length() <= 104
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes