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".
Definition
- Class:
- InsertZ
- Method:
- canTransform
- Parameters:
- String, String
- Returns:
- String
- Method signature:
- String canTransform(String init, String goal)
- (be sure your method is public)
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'.
Examples
"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"
"mvixrdnrpxowkasufnvxaq"
"mvizzxzzzrdzznzrpxozzwzzkazzzszzuzzfnvxzzzazzq"
Returns: "Yes"
"opdlfmvuicjsierjowdvnx"
"zzopzdlfmvzuicjzzsizzeijzowvznxzz"
Returns: "No"
"x"
"x"
Returns: "Yes"
"ndan"
"nzdan"
Returns: "Yes"
"bxcvums"
"bxzzcvzums"
Returns: "Yes"
"fcqgmppogt"
"fcqzzgmzppozgt"
Returns: "Yes"
"wpnimxqiaxylw"
"wzpnimzzxzqiazxyzlw"
Returns: "Yes"
"ahsibfwkstkurdfj"
"zahzzsizbfwkzsztkzurdfj"
Returns: "Yes"
"ghsmcdarcupumnoulky"
"ghsmcdazrcuzzpumzznzoulzzkyz"
Returns: "Yes"
"wvifonhhyqafvemhxivpip"
"wvizzzzzzfonhzhzyqzafzvemhxivpip"
Returns: "Yes"
"ngrfrekumpnciibqwvaegapkg"
"nzgrfrzezkzzzumpncizizbzqwvaegapkzzzg"
Returns: "Yes"
"vusmnfldjhxtpvppxhwubwpbehau"
"vzuzsmnzfzzldjhzxtzzpvpzpzxhzwubwpbzzehau"
Returns: "Yes"
"vvmvytymubymxwssblendjvwhuxygqv"
"zzvvzmvyztzzyzmzubyzmzxwzzssblendjvzwzhuxygzqv"
Returns: "Yes"
"cvajeeugmdwyllxptyxfmkkhcipklmuihtofaqnnhqystdkewe"
"cvajeeugmdwyllxptyxfmkkhcipklmuihtofaqnnhqystdkewe"
Returns: "Yes"
"q"
"zzzzzzzzzzzzzqzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
Returns: "Yes"
"eg"
"zzzzzzzzzzzzzzezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzgzzzz"
Returns: "Yes"
"qrl"
"zzzzzzzzzzzqzzzzzzzzzzzzzzzzzzzzrzzzzzzzzzlzzzzzzz"
Returns: "Yes"
"pkwvedmmsscwqtrmqxnlwevxjppkeckchjnbqdeaffwngahmt"
"pkwvedmmsscwqtzrmqxnlwevxjppkeckchjnbqdeaffwngahmt"
Returns: "Yes"
"uydqvkkobpsqflbwpqijkmtexorlrsuvkwexppumruvwgtif"
"uydqzvkkobpsqflbwpqijkmtexorlrsuvzkwexppumruvwgtif"
Returns: "Yes"
"lhdnxjvcvnmgbcbdhlogvvkukvunommrjwcexurcevwghot"
"lhdnxzjvcvnmgbzcbdhlogvvkuzkvunommrjwcexurcevwghot"
Returns: "Yes"
"wctuyccvjqphbtikemcprjrwt"
"wctuzyczzczvzjqphbztzzzzizzzkzemzcprjzzrzzzzwzztzz"
Returns: "Yes"
"fyjuklwagdcwegctokydjmeoe"
"fzyzjuzkzzlwazzzzgzdczzwzegczzzztokzydjmzzzezzzzoe"
Returns: "Yes"
"nnbwepkoafduxkkmljwevnrxc"
"nznbzwezpkzzozzzazfduxzkzkzmzzzljwzevzzzzzzznzrxcz"
Returns: "Yes"
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrzrrrrrrrrrrrrrr"
Returns: "Yes"
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
Returns: "No"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Returns: "Yes"
"mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
"mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
Returns: "No"
"l"
"illzz"
Returns: "No"
"vppvo"
"vvypzzpv"
Returns: "No"
"mfxxvfxvx"
"fmzffvvvmvz"
Returns: "No"
"dodpovdpodooo"
"zvodovpzddpodp"
Returns: "No"
"guguiugccicguicuu"
"ciggzuccgzugiguuc"
Returns: "No"
"ggkfkgifgkkgfkfkkfiig"
"gigiiikikzzkkffgggkf"
Returns: "No"
"ibccibybiyiyybcibicbycici"
"ciyizbzcccyybicciycyyyb"
Returns: "No"
"piixppixiqppxiqpxqpxppxiqxxxq"
"xqqxxzqqpipixpxixpizqiipqp"
Returns: "No"
"sxxxxaaxsaaaaaapxpsappxxxsssxssap"
"paaapasspaasaapzxpapapssaazps"
Returns: "No"
"bpbipbsppbsbbibiiiipbppbbpisipibsbipb"
"pzppsbbsbsbbsssbspppbbziipbbiipi"
Returns: "No"
"yyyxyxxxxyyxyyxxyyxxxyyyxyyyyyxyxxyyxxxxyxxxxxxxxy"
"yyxxyxxyyyxxxyyyxyxxyyxyyxyyxyxyxyyyxyyyxxxyyxxxxx"
Returns: "No"
"pppgpjgjpjjgpgppjpggpjggpppgjjgpppppjggpjpppgjpgpp"
"jpppggggggggpjggpjpjgpjjgpjpgggpgjpggjgppggjjppjgp"
Returns: "No"
"lolbdlllbobbolboddoddblollbbbldlbblobddlloolldlbbd"
"bbbdoobbdodbblobbobobloldooololddlddblboblodbobbol"
Returns: "No"
"hhcifkiihfikcckkkhikffhihikfifkfikckfciifkikickchk"
"kifcfhficihihchichkckihkffichkcihfikchififikiifckc"
Returns: "No"
"s"
"stsssttstttssttsttttsststttttttststtstttsssssststt"
Returns: "No"
"a"
"maapaammpmmamappmmmmammaamppammppaappppmppaaapmmap"
Returns: "No"
"s"
"vsyvvyymmysvsyvysyssyvsvymmyysyvsymvsymsvvvvyssvmv"
Returns: "No"
"s"
"ddsfsmsfismfmidfiimsdimmdmmdmfimdimssdmsimddmdfmss"
Returns: "No"
"g"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
Returns: "No"
"bdjblplvwmldthuytgcptorlswoyplhiuhjdkrnqssrdnwhwlu"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
Returns: "No"
"deproefcgvwbxtlyprvouovpklucrnsytexffhqjuhdiyutamp"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzszz"
Returns: "No"
"bibymqkuhqmnnamafgjcnnshhugiyljrsqacjvpabovpxwfwbg"
"zzzzzzzzzzzzkzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzozz"
Returns: "No"
"lhbwjwvtstnutpyvriqoiblggniaignipjtbetodiprgwtpids"
"zzjzzzzzzzzzzznzzzzzzzzzzzjzzzzzzzzzzzzzzzzzzzzzzz"
Returns: "No"
"vhcxsicvhoharvkawougxaiqihgawfhhfeifxongenhiuxwvmw"
"szzzkzzzzzzzzzzzzzzzzzzzzzzzzzzzzzlzzzzzzzzfzzzzzz"
Returns: "No"
"abc"
"abc"
Returns: "Yes"
"ab"
"zba"
Returns: "No"
"asdf"
"asdf"
Returns: "Yes"
"aaaaaaaa"
"a"
Returns: "No"
"as"
"sa"
Returns: "No"
"ab"
"ba"
Returns: "No"
"kcythetopcoder"
"topthekcycoder"
Returns: "No"
"fox"
"xof"
Returns: "No"
"baa"
"aabz"
Returns: "No"
"aba"
"aabz"
Returns: "No"
"f"
"ff"
Returns: "No"
"xof"
"fzox"
Returns: "No"
"fox"
"zzxof"
Returns: "No"
"fox"
"foxn"
Returns: "No"
"fox"
"fozxx"
Returns: "No"
"cc"
"czc"
Returns: "Yes"
"abcd"
"dcba"
Returns: "No"
"ab"
"az"
Returns: "No"
"a"
"aa"
Returns: "No"
"aba"
"baa"
Returns: "No"
"aaa"
"aa"
Returns: "No"
"f"
"zzzzzzzzk"
Returns: "No"
"abc"
"abcza"
Returns: "No"
"b"
"az"
Returns: "No"
"a"
"a"
Returns: "Yes"
"abc"
"cba"
Returns: "No"
"fox"
"foxxyz"
Returns: "No"
"abc"
"abczzzzzzzzzzzzzzza"
Returns: "No"
"abc"
"abcd"
Returns: "No"
"aaabaaa"
"aaaaaba"
Returns: "No"
"fox"
"wfzoxzz"
Returns: "No"
"a"
"ak"
Returns: "No"
"a"
"zba"
Returns: "No"
"fox"
"chchfox"
Returns: "No"
"fox"
"fxo"
Returns: "No"
"fox"
"fxozzzz"
Returns: "No"
"xy"
"zyxzz"
Returns: "No"
"abcd"
"aabcd"
Returns: "No"
"abc"
"abcdz"
Returns: "No"
"fox"
"foxxxxxxx"
Returns: "No"
"ab"
"baz"
Returns: "No"
"aaa"
"aaaa"
Returns: "No"
"fox"
"foxx"
Returns: "No"
"abca"
"aazzbc"
Returns: "No"
"ab"
"zzatab"
Returns: "No"
"fox"
"fobx"
Returns: "No"
"aa"
"aaa"
Returns: "No"
"fox"
"foxzy"
Returns: "No"
"abcd"
"zzbcdazz"
Returns: "No"
"fox"
"zozfxzz"
Returns: "No"
"abc"
"abdz"
Returns: "No"
"top"
"potz"
Returns: "No"
"fox"
"fooooox"
Returns: "No"
"ba"
"ab"
Returns: "No"
"ba"
"abzz"
Returns: "No"