Description

Given a phone number string, remove all spaces and dashes, then group digits into blocks of 3 with remaining digits in groups of 2. Return the reformatted number joined by dashes.

Examples

Input:number = "1-23-45 6"
Output:"123-456"
Explanation:

Digits 123456 grouped as 123-456.

Input:number = "123-4567"
Output:"123-45-67"
Explanation:

Remove dashes to get digits 1234567. Group into blocks of 3 from left, with remaining 4 digits split into two groups of 2: 123-45-67.

Input:number = "12-34 567 89"
Output:123-456-789
Explanation:

Remove spaces and dashes to get digits 123456789. Group into blocks of 3: 123-456-789.

Constraints

  • 2 ≤ number.length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!