FastPrepFastPrep
Problem Brief

Replace Nth Consonant

OA

See the Image Source section at the very bottom of the page for the original problem statement ๐Ÿˆโ€โฌ› ๐Ÿˆโ€

In a world of letters, thereโ€™s a secret mission hidden within a string of text. Your task is to find every nth consonant in the message and transform it into the next consonant in the alphabet, while preserving its original case. The journey of the consonants continues as 'b' becomes 'c', 'x' transforms into 'y', and when you reach 'z', it wraps back around to 'b' (or 'Z' to 'B'). Your goal is to follow this pattern, subtly shifting every nth consonant while leaving the rest of the message untouched, returning the newly crafted string when the job is done.

1Example 1

Input
message = "Codesignal", n = 3
Output
"CodeTignam"
Explanation

The consonants in "Codesignal" are "C-d-s-g-n-l". The third consonant is "s" which is replaced by "t". The sixth consonant is "l" which is replaced by "m". Thus, the resulting string is "CodeTignam".

public String replaceNthConsonant(String message, int n) {
  // write your code here
}
Input

message

"Codesignal"

n

3

Output

"CodeTignam"

Sign in to submit your solution.