Reformat a license key string into groups of fixed size separated by dashes, with letters in uppercase.
You are given a string representing an existing license key. It contains letters, digits, and dash characters (-). Your task is to reformat it so that:
k characters.Return the reformatted license key.
This is a straightforward string-processing problem: normalize the characters first, then rebuild the formatted output from right to left or left to right while respecting the group size.
s containing alphanumeric characters and dashes.k, the required group size for all groups except possibly the first.k.Example 1
Input
s = "5F3Z-2e-9-w", k = 4
Output
"5F3Z-2E9W"
Explanation
After removing dashes and converting to uppercase, the string becomes 5F3Z2E9W. With k = 4, it is already one group of length 4 followed by another group of length 4, so the result is 5F3Z-2E9W.
Example 2
Input
s = "2-5g-3-J", k = 2
Output
"2-5G-3J"
Explanation
Normalize to 25G3J. Grouping from the end with size 2 gives 2-5G-3J.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.