ARight
SRM 845 · 2023-03-02 · by misof
Problem Statement
Given is a
The string S has at least K characters, and none of its last K characters are 'a's.
Your task is to simultaneously shift each 'a' in S by K positions to the right. (The other letters in S must remain in their original relative order.)
Return the resulting string.
Constraints
- K will be between 1 and 50, inclusive.
- S will have between K and 100 characters, inclusive.
- Each character in S will be a lowercase English letter ('a'-'z').
- None of the last K characters in S will be 'a'.
Statement by TopCoder, Inc. — view the original on the archive.
"topcoder" 3 Returns: "topcoder"
No 'a's to move, so the resulting string is the same as the initial one.
"bananas" 1 Returns: "bnanasa"
"aaaaabbbbb" 5 Returns: "bbbbbaaaaa"
"abracadabrahocuspocus" 6 Returns: "brcdbrahoacauaspaocus"
"aardvark" 1 Returns: "raadvrak"
Submissions are judged against all 67 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ARight with a public method string modify(string S, int K) · 67 test cases · 2 s / 256 MB per case