License Key Formatting
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A license key s is a string of letters, digits and dashes '-'. The dashes currently split it into arbitrary chunks. Reformat it using a group size k.
Discard every dash and convert all letters to **uppercase**. Then split the remaining characters into groups separated by single dashes, where every group has exactly k characters **except the first group**, which may be shorter but must contain at least one character. Group from the right so only the first group can be short.
Return the reformatted key. If no letters or digits remain, return an empty string.
Examples
Constraints
- 1 <= s.length <= 10^5
- `s` consists of English letters, digits, and dashes `'-'`
- 1 <= k <= 10^4
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.