Replace Every Nth Consonant
Problem statement
You are given a string message and a positive integer n. Scan consonant letters in message order, ignoring vowels and nonletters.
Replace every nth consonant with the next consonant in the sequence bcdfghjklmnpqrstvwxyz. Preserve case, and wrap z to b. Leave every other character unchanged.
Function
replaceEveryNthConsonant(message: String, n: int) → StringExamples
Example 1
message = "CodeSignal"n = 3return = "CodeTignam"S is the third consonant and becomes T; l is the sixth consonant and becomes m.
Example 2
message = "xyz"n = 2return = "xzz"y is the second consonant and advances to z.
Constraints
0 <= message.length <= 1000001 <= n <= 100000