TopcoderARCHIVE
SRM · Problem 17997

ARight

Problem statement, definition, constraints, and public examples.

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

  1. "topcoder"
    3
    Returns: "topcoder"
    No 'a's to move, so the resulting string is the same as the initial one.
  2. "bananas"
    1
    Returns: "bnanasa"
  3. "aaaaabbbbb"
    5
    Returns: "bbbbbaaaaa"
  4. "abracadabrahocuspocus"
    6
    Returns: "brcdbrahoacauaspaocus"
  5. "aardvark"
    1
    Returns: "raadvrak"
  6. "aardvark"
    2
    Returns: "rdaavrka"
← All problems