InsertZ
SRM 587 · 2013-06-25 · by ir5
Problem Statement
You are given two
Your goal is to transform init into goal. The only operation you are allowed to do is to insert the character 'z' anywhere into init. You can repeat the operation as many times as you want, and each time you can choose any position where to insert the 'z'.
For example, if init="fox", you can transform it to "fzox" in one operation. Alternately, you can transform "fox" into "zzzfoxzzz" in six operations. It is not possible to transform "fox" into any of the strings "fx", "foz", "fxo", "foxy".
Return "Yes" (quotes for clarity) if it is possible to transform init into goal. Otherwise, return "No".
Notes
- Note that the return value is case sensitive.
Constraints
- init and goal will each contain between 1 and 50 characters, inclusive.
- Each character of init and goal will be a lowercase letter ('a'-'z').
- init will not contain the letter 'z'.
"fox" "fozx" Returns: "Yes"
By inserting 'z' to the position bettween 'o' and 'x' in "fox", we obtain "fozx".
"fox" "zfzoxzz" Returns: "Yes"
You may perform the operation multiple times.
"foon" "foon" Returns: "Yes"
In this case init and goal are equal. You do not have to perform the operation.
"topcoder" "zopzoder" Returns: "No"
"aaaaaaaaaa" "a" Returns: "No"
Submissions are judged against all 111 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class InsertZ with a public method string canTransform(string init, string goal) · 111 test cases · 2 s / 256 MB per case