The Reformat Phone Number problem asks you to normalize a phone number by removing spaces and dashes, then regrouping digits into blocks of 3, except when 1 or 2 digits remain (form a group of 2+2 or just 2). This easy coding problem tests string chunking logic. The string interview pattern is demonstrated.
Activision asks this to verify careful string chunking with a special edge case for the final grouping. It's a practical implementation problem testing attention to the "2-digit leftover" rule.
Clean + chunk + special last group. Remove all spaces and dashes. While length > 4: take 3 digits. For remaining 4: split as 2+2. For remaining 3: take as one group. For remaining 2: take as one group. Join with '-'.
s="1-23-45 6". Clean: "123456". Length=6.
s="123 4-567 89 10". Clean: "1234567890". Length=10.
String chunking problems with special tail handling require processing the tail differently from the body. Always handle the tail cases last: if remaining=4 → 2+2; if remaining=3 → 3; if remaining=2 → 2. Process the main body in fixed blocks first. Practice similar "formatted output with special tail" problems: "split string into k-char groups," "format credit card number," "break text into lines."