JuniorString
License Key Formatting
You are given a license key represented as a string s that consists of only alphanumeric characters and dashes. The string is separated into n + 1 groups by n dashes. You are also given an integer k.
Reformat the string s so that:
- Each group contains exactly
kcharacters, except for the first group. - The first group may be shorter than
k, but must still contain at least one character. - A dash must be inserted between every two groups.
- All lowercase letters must be converted to uppercase.
Return the reformatted license key.
Example 1
Input
s = "5F3Z-2e-9-w", k = 4Output
"5F3Z-2E9W"The string
s has been split into two parts, each with 4 characters, and the extra dashes are removed.Example 2
Input
s = "2-5g-3-J", k = 2Output
"2-5G-3J"The string
s has been split into three parts, each with 2 characters except the first part, which is shorter.Constraints
- 1 <= s.length <= 10^5
- s consists of English letters, digits, and dashes '-'
- 1 <= k <= 10^4