Tap here to switch tabs
Problem
Submissions

Problem: License Key Formatting

med
30 min
Try to solve the License Key Formatting problem.

Statement

Given a string s representing a license key and an integer k, reformat s so that the groups of characters are separated by dashes and each group contains exactly k characters, except possibly the first group, which may contain fewer than k characters.

The reformatted string should use uppercase letters only. Remove all existing dashes from s before grouping the characters.

Return the reformatted license key.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s consists of English letters, digits, and dashes '-'.

  • 1≤1 \leq k ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: License Key Formatting

med
30 min
Try to solve the License Key Formatting problem.

Statement

Given a string s representing a license key and an integer k, reformat s so that the groups of characters are separated by dashes and each group contains exactly k characters, except possibly the first group, which may contain fewer than k characters.

The reformatted string should use uppercase letters only. Remove all existing dashes from s before grouping the characters.

Return the reformatted license key.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s consists of English letters, digits, and dashes '-'.

  • 1≤1 \leq k ≤104\leq 10^4