ARight
SRM 845 · 2023-03-02 · by misof
SRM 845 · 2023-03-02 · by misof · Simple Search, Iteration, String Manipulation
Problem Statement
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'.
Examples
0)
"topcoder" 3 Returns: "topcoder"
No 'a's to move, so the resulting string is the same as the initial one.
1)
"bananas" 1 Returns: "bnanasa"
2)
"aaaaabbbbb" 5 Returns: "bbbbbaaaaa"
3)
"abracadabrahocuspocus" 6 Returns: "brcdbrahoacauaspaocus"
4)
"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.
Coding Area
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