FunctionRacerProblemsRace

Stretch Each Character

BeginnerStringsPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems