Replace Every Nth Consonant
Learn this problemProblem 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) → StringExamples
Example 1
message = "CodeSignal"n = 3return = "CodeTignam"Constraints
🍊🍊More Meta problems
- Count Fully Used BatteriesOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Minimum Operations for a Stepwise SequenceOA · Seen Jul 2026
- Most Frequent Reduced DigitOA · Seen Jul 2026
- Plan a Minimum-Cost Round TripONSITE INTERVIEW · Seen Jul 2026
- Merge Three Sorted ArraysPHONE SCREEN · Seen May 2026
- Highest Rating Price RatioOA · Seen Mar 2026
- Diagonal Traverse (for E4 ;)PHONE SCREEN · Seen Mar 2025