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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

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
String Building
Modular Arithmetic
Formatting
Two-Pass Scan
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: raw containing alphanumerics and -, and an integer k >= 1.
  • Output: the characters of raw (dashes removed, letters uppercased), split into groups of k from 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...


Submit Your Answer
Markdown supported