EqualizeStrings
TCO10 Round 1 · 2010-04-11 · by soul-net
Problem Statement
You have two
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').
"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".
"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.
"programmingcompetitionsrule" "programmingcompetitionsrule" Returns: "programmingcompetitionsrule"
If both strings are equal, then you don't need any moves.
"topcoderopen" "onlinerounds" Returns: "onlcndaoondn"
"aazanamaobnbmbobpxxxyyyzzz" "azanamaobnbmbobpbzyxzyxzyx" Returns: "aaaaaaaaabbbbaaaaxxxyyxzyx"
Submissions are judged against all 70 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class EqualizeStrings with a public method string getEq(string s, string t) · 70 test cases · 2 s / 256 MB per case