Input: A = "abbaac", B = "abbbbaaac"
Output: YES
Explanation: A can be converted into B by performing the operations as follows:
- Insert b between 2nd and 3rd characters of A. ( A becomes abbbaac )
- Insert b between 2nd and 3rd characters of A.( A becomes abbbbaac )
- Insert a between 6th and 7th characters of A. ( A becomes abbbbaaac )
Input: A = "xyzz", B = "xyyzz"
Output: NO
A = {(a, 1), (b, 2), (a, 2), (c, 1)}
B = {(a, 1), (b, 4), (a, 3), (c, 1)}
Let's generalize the encoding of 2 strings as :
A = {(a1, x1), (a2, x2), (a3, x3).....(aN, xN)}
B = {(b1, y1), (b2, y2), (b3, y3)....(bM, yM)}
Now, A can be made equal to B, if the following 3 conditions are satisfied:
- N = M
- ai = bi, for i = 1, 2, 3....N
- Either (xi = yi ) or (xi < yi and xi ? 2) for i = 1, 2, 3....N