Description

Reformat a license key string so that each group has exactly K characters except the first group. Change all letters to uppercase and remove dashes.

Examples

Input:s = "5F3Z-2e-9-w", k = 4
Output:"5F3Z-2E9W"
Explanation:

Groups of 4.

Input:s = "2-5g-3-J", k = 2
Output:"2-5G-3J"
Explanation:

Remove dashes to get "25g3J", convert to uppercase: "25G3J". Group from right in groups of 2: "2-5G-3J". The first group has 1 character.

Input:s = "a-a-a-a-a", k = 3
Output:AAA-AA
Explanation:

Remove all dashes, convert to uppercase, then group from right: first group has 2 chars, second group has 3 chars.

Constraints

  • 1 ≤ s.length ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!