Problem · String
Shift Every K-th Consonant
Learn this problemProblem statement
You are implementing a simple substitution cipher that affects only consonant characters in a string memo.
Read the consonants in memo from left to right. Every k-th consonant is shifted to the following consonant in the alphabet, while vowels and all other characters remain unchanged. In other words, consonants numbered k, 2 * k, 3 * k, and so on are shifted.
- The consonants are
b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y, andz. - When shifting from
z, wrap around tob. - Preserve the case of every shifted character.
Return the transformed memo.
A solution with time complexity no worse than O(memo.length^2) will fit within the execution time limit.
Function
solution(memo: String, k: int) → StringExamples
Example 1
memo = "CodeSignal"k = 3return = "CodeTignam"The consonants are C, d, S, g, n, and l. The third consonant S shifts to T, and the sixth consonant l shifts to m.
Example 2
memo = "Quiz, Citizenship, puZZle"k = 5return = "Quiz, Citibenship, quZZle"The fifth consonant is the lowercase z in Citizenship, so it wraps to b. The tenth consonant is the first p in puZZle, so it shifts to q.
More Tiktok problems
- Can Reach the Exit with TeleportsOA · Seen Jul 2026
- Check Monotonic TriplesOA · Seen Jul 2026
- Count Access Code PairsOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Sort Matrix BordersOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Validate 3x3 Digit WindowsOA · Seen Jul 2026
- Count Skipped Numbers After SubtractionsOA · Seen Jul 2026