Stretch Each Character
Return the string made by writing every character of s exactly k times in a row, keeping the characters in their original order. For example "ab!" with k = 3 gives "aaabbb!!!".
Spaces are stretched like any other character. When k is 0 or s is empty, return the empty string.
Example 1
s "ab!"
k 3
returns "aaabbb!!!"
Each of a, b and ! is written three times.
Example 2
s "hey"
k 1
returns "hey"
With k = 1 every character is written once, so the string does not change.
Constraints
0 <= len(s) <= 200 <= k <= 5shas lowercase letters, digits, spaces and the symbols!and?only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Student Attendance RecordBeginner
- Sum of Digits in TextBeginner
- Truncate SentenceBeginner
- Two String Lists Spell the Same WordBeginner
- Vowel and Consonant TallyBeginner
- Abbreviate Long WordsEasy
- Buddy StringsEasy
- Caesar CipherEasy