Problem Statement
Given is a String S of lowercase English letters ('a'-'z') and an int K.
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.
Definition
- Class:
- ARight
- Method:
- modify
- Parameters:
- String, int
- Returns:
- String
- Method signature:
- String modify(String S, int K)
- (be sure your method is public)
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
"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"
"aardvark"
2
Returns: "rdaavrka"