We’re preparing your current view and syncing the latest data.
You are given a license key represented as a string s that consists of only alphanumeric characters and dashes. The string is separated into groups by dashes. You are also given an integer k. We want to reformat the string s such that each group contains exactly k characters, except for the first group which could be shorter than k but must contain at least one character. Furthermore, there must be a dash inserted between two groups and all lowercase letters should be converted to uppercase.
Return the reformatted license key.
A string s containing alphanumeric characters and dashes, and an integer k.
Return a string representing the reformatted license key as per the described format.
1 <= s.length <= 10^5 s consists of alphanumeric characters and dashes. 1 <= k <= 10^4
Example 1
Input
s = "2-4A0r7-4k","k = 4"
Output
"24A0-R74K"
Explanation
Remove dashes and convert letters to uppercase: "24A0R74K". Then divide into groups of k=4 starting from the right: "24A0" and "R74K".