LexStringWriter
SRM 321 · 2006-10-02 · by Mike Mirzayanov
Problem Statement
You have a special machine called a LexStringWriter. It has a display that initially shows the
Return the minimal number of button presses necessary to print all of the letters in s in alphabetically order. All occurrences of all letters in s must be printed, so if 'a' appears 3 times, for example, 'a' must be printed 3 times.
Constraints
- s will contain between 1 and 50 characters, inclusive.
- s will contain only lowercase letters ('a'-'z').
"aaa" Returns: 5
Press: enter, right, enter, right, enter.
"ba" Returns: 4
You should print the letter 'a' first.
"abba" Returns: 9
"acbbc" Returns: 12
Print the rightmost letter 'c' before the leftmost.
"a" Returns: 1
Submissions are judged against all 110 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LexStringWriter with a public method int minMoves(string s) · 110 test cases · 2 s / 256 MB per case