FastPrepReplace Each Consonant

Replace Each Consonant

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

Replace every consonant letter in text with the next consonant in bcdfghjklmnpqrstvwxyz. Preserve case, wrap z to b, and leave vowels and nonletters unchanged.

Function

replaceConsonants(text: String) → String

Examples

Example 1

text = "Code Z!"return = "Dofe B!"

C becomes D, d becomes f, and Z wraps to B; vowels and punctuation remain.

Example 2

text = "aeiou"return = "aeiou"

Vowels are unchanged.

Constraints

  • 0 <= text.length <= 100000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String replaceConsonants(String text) {
    // Write your code here.
}
text"Code Z!"
expected"Dofe B!"
Checking account…