FastPrepReplace Every Nth Consonant

Replace Every Nth Consonant

ZipRecruiter logoZipRecruiter● EasyFULLTIMENEW GRADOA
Learn

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) → String

Examples

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 <= 100000
  • 1 <= n <= 100000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String replaceEveryNthConsonant(String message, int n) {
    // Write your code here.
}
message"CodeSignal"
n3
expected"CodeTignam"
Checking account…