As reported: Capital One Senior Software Engineer (Plano), CodeSignal online assessment, Sep 2024: four questions in 70 minutes, with 14 days to take it — a very easy first question; this one, given a string such as
"CodeSignal"andn; a question on audiobook listening times and logs; and a DP question similar to LeetCode 3101.
Given a string message and an integer n, replace every n-th consonant of the message (the n-th, 2n-th, 3n-th, … counting only consonants) with the next consonant of the English alphabet. Keep the letter's case; z wraps around to b. Vowels (a e i o u, either case) and non-letters stay unchanged and are not counted.
Example
message = "CodeSignal", n = 3 -> "CodeTignam"
consonants: C d S g n l -> the 3rd (S) becomes T, the 6th (l) becomes m
message = "Zebra-493?", n = 2 -> "Zecra-493?"
Constraints: 0 ≤ message.length ≤ 10^5; 1 ≤ n ≤ 10^5; message holds printable ASCII.
Code runner format: line 1 message (JSON string), line 2 n. Implement replaceNthConsonants(message, n); the harness prints the new string.
Clarifications
yis a consonant.- The next consonant skips vowels:
d → f,h → j,n → p,t → v,z → b.