Regroup a Workspace License Key Into Fixed-Size Dash Blocks
Last updated: November 29, 2026
Quick Overview
Given a license key string with letters, digits, and dashes in arbitrary places, and a group size k, reformat it so every group has exactly k uppercase characters except the first, which may be shorter but not empty, with groups joined by single dashes.
0
0
0 solved
Given a license key string with letters, digits, and dashes in arbitrary places, and a group size k, reformat it so every group has exactly k uppercase characters except the first, which may be shorter but not empty, with groups joined by single dashes.
This kind of question appears in Google online assessments as a quick test of clean string building. The interviewer is looking for the observation that grouping is anchored from the end, and for linear-time construction instead of repeated string concatenation.
What the Interviewer Expects
- Strips existing dashes and uppercases characters
- Realizes the short group must be the first one and computes its length with modulo
- Builds the result with a list and join, not repeated concatenation
- Handles input that is only dashes
- Gives O(n) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Do it in place on a character array with O(1) extra space.
- What if the shortest group must be the last one instead?
- How would you validate a checksum digit embedded in the key?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
rawcontaining alphanumerics and-, and an integerk >= 1. - Output: the characters of
raw(dashes removed, letters uppercased), split into groups ofkfrom the right, so only the f...
High-Level Design
Collect the meaningful characters first. If there are n of them, the first group has n % k characters, or k when that remainder is zero. After that every group is exactly k, so we slice the li...