476. License Key Formatting
EasyString
Remove all dashes, convert to uppercase, then regroup into groups of k characters from the right (the first group may be shorter), joined by dashes.
Input format
Line 1: s Line 2: k
Output format
The formatted key.
Example 1
Input
5F3Z-2e-9-w 4
Output
5F3Z-2E9W
Example 2
Input
2-5g-3-J 2
Output
2-5G-3J
Constraints
1 ≤ |s| ≤ 10⁵; s has at least one non-dash character
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…