Statistics

Problem Statement for "EqualizeStrings"

Problem Statement

You have two Strings, s and t, and you want them to be equal. You can change individual letters in the Strings, but you cannot add or remove letters. In a single move, you can change any one letter in one String to the letter that comes directly before or after it in the alphabet. The alphabet wraps around, so you can also change 'a' to 'z' or 'z' to 'a'. You want to make the two Strings equal using the minimum possible number of moves. Return the resulting String. If there are multiple answers, return the one that comes earliest alphabetically.

Definition

Class:
EqualizeStrings
Method:
getEq
Parameters:
String, String
Returns:
String
Method signature:
String getEq(String s, String t)
(be sure your method is public)

Notes

  • A String comes earlier lexicographically than another one of the same length if and only if it has a character closer to the beginning of the alphabet in the first position at which they differ.

Constraints

  • s will contain between 1 and 50 characters, inclusive.
  • s and t will contain the same number of characters.
  • Each character of s and t will be a lowercase letter ('a'-'z').

Examples

  1. "cat"

    "dog"

    Returns: "caa"

    Use 1 move to change 'd' to 'c', 12 moves to change 'o' to 'a', 6 moves to change 'g' to 'a' and 7 moves to change 't' to 'a' for a total of 26 moves to get both Strings equal to "caa".

  2. "abcdefghijklmnopqrstuvwxyz"

    "bcdefghijklmnopqrstuvwxyza"

    Returns: "abcdefghijklmnopqrstuvwxya"

    Change every letter in t to its previous letter in the alphabet, using exactly one move per letter, with the exception of the last character; it's preferable to change the 'z' in s to 'a' to obtain a lexicographically earlier solution.

  3. "programmingcompetitionsrule"

    "programmingcompetitionsrule"

    Returns: "programmingcompetitionsrule"

    If both strings are equal, then you don't need any moves.

  4. "topcoderopen"

    "onlinerounds"

    Returns: "onlcndaoondn"

  5. "aazanamaobnbmbobpxxxyyyzzz"

    "azanamaobnbmbobpbzyxzyxzyx"

    Returns: "aaaaaaaaabbbbaaaaxxxyyxzyx"

  6. "oxj"

    "imo"

    Returns: "imj"

  7. "tdnzvghl"

    "nvhhjmzs"

    Returns: "nahajgal"

  8. "gskstxncxwploxjebv"

    "yzjaiksblsjeeomhpx"

    Returns: "asjaianblsjeeojeav"

  9. "zzsjzcrhulejffoajqlxyfwqevdqkhudcizcmxxfshomk"

    "ksmjzoujccnbcazakzlhsmtfboteseqkninwqeviegumc"

    Returns: "asmjzcrhacebcaoajqlasftfboaekeqdcinamavfagomc"

  10. "ylygvkabtioalcsdwuotigpugjnmbkcmvbxoipwhavuvnbpke"

    "tfwpzlgxdqkwgpfjdyxqbhfbicwlbrzsqzxmfrxqjsnhbkmtl"

    Returns: "tfwgvkaaaikagaadauoqbgfagcnlbkamqaxmfpwhasnabbmke"

  11. "ocfmfrgrphpuqpvubnugufprdrwqssolndeveuhjtinztffgrc"

    "pxonbiolxlzjppbonivgllbherjsvbczglatewduemrmtxdftk"

    Returns: "oafmbiglphpjppaobiuglfahdraqsacagdateudjainatadfrc"

  12. "mltmv"

    "rukyd"

    Returns: "mlkma"

  13. "norkqfb"

    "pdpqvsi"

    Returns: "ndpkqab"

  14. "rdlaokqchxbocbmzhjtxp"

    "oqwvqvogifvnerkaxxojs"

    Returns: "oalaokochaancakaaaoap"

  15. "qqyuhokxrunltnvnekbbrjtzxmuyxqwwgimkoqkcxzz"

    "ngzpwjwajatycdmosbfqgyxlqprxidkitsaarcmrbfv"

    Returns: "ngypajkajanaadmnabbagataqmrxaakaaiaaoakaaav"

  16. "eolnscassggpwauarbydbfynejltrnzbgxglqdoaordsytfb"

    "xlaxnunkssqaabzrmdvzcninvpjmclcmnrdhhybchdfxrjra"

    Returns: "alannaaksggaaauambvabfanajjmalabgrdhhaaahadsrjfa"

  17. "eltemmzycsgscdiqcvsyumnqktzadmvjhaznpcwffilzyakyim"

    "wrydxbjbmtedhakjsfwafevlpvyunwklaxikdyuhvvvrdedqpi"

    Returns: "altdmbaacseacaijaasaaenlktyadmkjaaakdaufaalraadqii"

  18. "rzbvbk"

    "qqwutu"

    Returns: "qqauak"

  19. "qsfhrjtbi"

    "biyfknllt"

    Returns: "aiafkjlbi"

  20. "uhkwwiggjrbstk"

    "tygrowkcrygrfo"

    Returns: "tagroagcjrbrak"

  21. "ivwoltddkdypqeyezibbjdpwfyddkacreuiphnkvnwelqy"

    "onygtbgpxwkokycjexhsqslvwjhbyzasgihcoqfpcqrmme"

    Returns: "inwgladdaaaokaaeaabajalvaadbaaareihahnfpcqalma"

  22. "ftdijyhitvwpscpmarwsgtuexrxtmvlbzadqexjmagwmxful"

    "pwdcdonjulftqjitkancxasosxcgjgkegorwcwzhpvmogqmn"

    Returns: "ftdcdohitlapqcimaanaaasesraajakbaaaqcwahaammafml"

  23. "qgqfcgwspdojlsieixbyimduphsovejaiwkzsngkhmvanuyrvy"

    "xwqkizppkmaixgguyzylzcuduvosrztfrbipjjazsdiyzkpfwm"

    Returns: "qaqfcappkdailggaaxaaacaapaoorajaiaipjjaahdaankpfvm"

  24. "locgy"

    "oolbn"

    Returns: "locbn"

  25. "qwppatznd"

    "aghymptmc"

    Returns: "aahpaptmc"

  26. "tilgbbxsfrmorazhalkoquf"

    "hubjoupujbftzibklqnwugz"

    Returns: "hibgaapsfaforaahalkoqaa"

  27. "edjocwejlnhifmcvchvpknwptogtfjnc"

    "kxfffetsdaunugqcttavkucwzvlrfgec"

    Returns: "eaffcaajdaaiagaaahapknaptogrfgec"

  28. "cflzgaifhmyrzxqowhwvpevqerqaweesrhaxyrxpycxiujhn"

    "vgpwrtaebzgnxdtylmweeiyrmvyqzfqyehhuhwnqfdydhvpy"

    Returns: "aflwgaaebaanxaqolhwaeevqerqaweesahauarnpacxdajhn"

  29. "vmetkijzbisfkhpsyapaljmzdjgjdhwuyunxquz"

    "vvpseeaujlhthrnlysgdihudiwueochxueftiuo"

    Returns: "vmeseeaubihahhnlyagaihmadaaedcauuaftiuo"

  30. "a"

    "a"

    Returns: "a"

  31. "a"

    "z"

    Returns: "a"

  32. "b"

    "n"

    Returns: "b"

  33. "o"

    "b"

    Returns: "a"

  34. "b"

    "n"

    Returns: "b"

  35. "jinmys"

    "ysosru"

    Returns: "ainmrs"

  36. "bpanyo"

    "zonman"

    Returns: "aoaman"

  37. "wzxjrusb"

    "ihacfusz"

    Returns: "aaacfusa"

  38. "zyyoyann"

    "zzpnzzzm"

    Returns: "zypnyanm"

  39. "uqbpjfzshdzbxyoj"

    "azznxcwyzdhiaosw"

    Returns: "aqanacwsadabaooa"

  40. "zomybaaozmznmbmb"

    "amanpznoannaoynm"

    Returns: "amanaaaoamnamamb"

  41. "krzyzhqiqgpqgzohvkkqhoolaohgnj"

    "hxaixcqpkiwaaezplwbxninbvpsdvf"

    Returns: "hraaxcqikgpaaaohlkbqhinbaohdnf"

  42. "ynyybpazmzmbpamopooobpbyzopbmo"

    "ybzoaabazoznponaazopopnpmbbanp"

    Returns: "ybyoaaaaaoabpamaaoooapbpaaaamo"

  43. "wosqiomtnygzcvcynjbixipeimyqvjbrzviijwdwwjyygaxwj"

    "yejgtpqinhdwkwwiggrcjqzuozdowzzwfkdzatjncomnkivtq"

    Returns: "wejgiominadwcvaaggacaipaiaaovaarakdaatdnajmngavtj"

  44. "omznoponanomobzonyoppynmamzaaynonbzyymazypnnybyaz"

    "mpobzzbnzbnpmzzoyynbybzmobbpabpmzboybpbaympbnppam"

    Returns: "mmobopanabnmmazonynapanmabaaaanmnboyamaaymnbnapaa"

  45. "apvphrdiqnudqbtebqzeonovwcudzpczfzqmqtwhismavfexvd"

    "dlsthqydtxtywyxmmqikzsdltyrxxoddaxwjowmjtfhrfhetxo"

    Returns: "alsphqadqntaqatebqaeondltaraxocaaxqjotmhiahaafetvd"

  46. "nnapbbmobmpynppnopbybnonyppobnamoaaynmnmyzbaoymaoo"

    "zpymzoapabzaoobonmaoyyozzapnbbyayomybmmbpnnbymyayy"

    Returns: "nnamaaaoabpanoannmaoanonyapnbbaaoaaybmmbpnbaommaoo"

  47. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  48. "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"

    "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"

    Returns: "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"

  49. "b"

    "m"

    Returns: "b"

  50. "b"

    "o"

    Returns: "a"

  51. "abcdefghijklmnopqrstuvwxyznopqrstuvwxyzabcdefghijk"

    "nopqrstuvwxyzabcdefghijklmabcdefghijklmnopqrstuvwx"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  52. "abcdefghijklmnopqrstuvwxyzcdefghijklmnopqrstuvwxyz"

    "zyxwwwwwwwwbbbbbcccccccccczyxwwwwwwwwbbbbbcccccccc"

    Returns: "aaaaaaaaaakbbbaaaaaaaaaaaaaaaaaaaaklmbaaaaaaaaaaaa"

  53. "bcde"

    "zxvd"

    Returns: "aaad"

  54. "b"

    "y"

    Returns: "a"

  55. "b"

    "z"

    Returns: "a"

  56. "jaksdfhsdf"

    "jhgfdljksd"

    Returns: "jagadfhkad"

  57. "z"

    "c"

    Returns: "a"

  58. "bbbbb"

    "nopzy"

    Returns: "baaaa"

  59. "c"

    "o"

    Returns: "c"

  60. "z"

    "b"

    Returns: "a"

  61. "ab"

    "ac"

    Returns: "ab"

  62. "b"

    "p"

    Returns: "a"

  63. "bboo"

    "otch"

    Returns: "aach"

  64. "j"

    "z"

    Returns: "a"

  65. "x"

    "b"

    Returns: "a"

  66. "zzz"

    "bbb"

    Returns: "aaa"

  67. "c"

    "n"

    Returns: "c"

  68. "m"

    "z"

    Returns: "a"

  69. "j"

    "u"

    Returns: "j"

  70. "z"

    "z"

    Returns: "z"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: