Problem · String

Replace Every Nth Consonant

Learn this problem
EasyMeta logoMetaINTERNOA
See Meta hiring insights

Problem statement

Note ->> See the Image Source section at the very bottom of the page for the original problem statement and etc.. 🐰🐰

Given a string message and an integer n, your task is to replace every nth consonant with the next consonant in alphabetical order, ensuring the case remains consistent (e.g., 'b' becomes 'c', 'x' becomes 'y', and 'Z' becomes 'B'). The consonants follow this order: 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z', and if the consonant is 'z' or 'Z', it wraps around to 'b' or 'B'. While your solution doesn't need to be the most efficient, it should still run smoothly with a time complexity no worse than O(message.length^2).

🫧𓇼Credit to Charlotte𓏲*ੈ✩‧₊˚🎐

Function

metaReplaceConsonant(message: String, n: int) → String

Examples

Example 1

message = "CodeSignal"n = 3return = "CodeTignam"
🍊

Constraints

🍊🍊

More Meta problems

drafts saved locally
public String metaReplaceConsonant(String message, int n) {
  // write your code here
}
message"CodeSignal"
n3
expected"CodeTignam"
checking account