Showing:
Handle Score
@Ibrahim Nash 5765
@akhayrutdinov 5111
@mb1973 4993
@Quandray 4944
@saiujwal13083 4506
@sanjay05 3762
@marius_valentin_dragoi 3516
@sushant_a 3459
@verma_ji 3341
@KshamaGupta 3318
Transform String
Medium Accuracy: 23.88% Submissions: 522 Points: 4

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.

Example 1:

Input:
A = "abd"
Output: 1
Explanation: The conversion can take place in
1 operation: Pick 'b' and place it at the front.

Example 2:

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)

Constraints:
1<= A.length(), B.length() <= 104