FunctionRacerProblemsRace

License Key Formatting

EasyStringsPython, JavaScript, TypeScript, Java, C++

s is a license key made of letters, digits and dashes. Rewrite it like this: remove all dashes, change letters to uppercase, then split the characters into groups of k separated by dashes. Every group has exactly k characters except possibly the first, which may be shorter (but not empty). Return the new key, or an empty string if s has no letters or digits.

Example 1

s "5F3Z-2e-9-w"
k 4
returns "5F3Z-2E9W"

Characters 5F3Z2E9W split into 5F3Z and 2E9W.

Example 2

s "2-5g-3-J"
k 2
returns "2-5G-3J"

Characters 25G3J: 2-5G-3J.

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