# Transform a string to another using minimum of the given operation

EDIT: The link’s answer is correct, I was at fault for not checking the cases. Thanks for concern and sorry for inconvenience/confusion

We got this question in yesterday evening’s Lab test (Make your code pass all test cases, time given-45 min).

My Query- The question (of our exam) stated that the two strings contain uppercase letters, and no more than 20 letters (so that weak algos also pass). Nowhere were we given that all characters of the string are distinct.

If I follow the solution given at that site, the code fails for cases where string has repeating characters-

Eg- ALLOOO OOOLLA

It is easily seen that we can convert string 1 to string 2 in three operation, but the code given in link prints more than 3. Similarly-

OOOOLLA ALLOOOO

This string will always take 3 operations irrespective of length, while the code in link will print an answer which depends on length.

The Question- What is the correct solution of the above problem, if strings of repeating characters are included (if possible)?

(PS: Please help, bichaare bachche ki CG ka sawaal hai )

For the first example you provided, I guess the answer is 5. Because, ALLOOO -> LALOOO -> LLAOOO -> OLLAOO -> OOLLAO -> OOOLLA. I can’t find any other way where we can transform string A to B in 3 steps. And, the code at the site gives correct answer for the second case as 3 correctly. Link for the code.

1 Like

Yes, I realized the mistake, thanks to you. I should really not try making test cases etc. when tensed. Thanks for your answer, I realized my error.