dsa · easy

License Key Formatting

s is a license string of English letters, digits, and dashes. Reformat it:

Arguments

If nothing but dashes remains, return an empty string.

Example

s = "5F3Z-2e-9-w", k = 4. Stripping dashes and uppercasing gives 5F3Z2E9W (8 characters). Two groups of 4 from the right: "5F3Z-2E9W".

s = "2-5g-3-J", k = 2 → characters 25G3J. Left leftover 2, then pairs → "2-5G-3J".

Constraints

1 <= s.length <= 10^5 1 <= k <= 10^4 s contains only English letters, digits, and dashes Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
'5F3Z-2e-9-w'
4

Expected:
5F3Z-2E9W

Example 2

Input:
'2-5g-3-J'
2

Expected:
2-5G-3J

Open in the Dojo editor