Tap here to switch tabs
Problem
Submissions

Problem: Reformat Phone Number

med
30 min
Try to solve the Reformat Phone Number problem.

Statement

You are given a phone number as a string number. The string number consists of digits, spaces ' ', and dashes '-'.

Reformat the phone number by applying the following steps:

  1. Remove all spaces and dashes.

  2. Group the digits from left to right into blocks of length 33 until 44 or fewer digits remain.

  3. For the remaining digits:
    • If 22 digits remain, place them in a single block of length 22.
    • If 33 digits remain, place them in a single block of length 33.
    • If 44 digits remain, split them into two blocks of length 22 each.

Join all blocks using the separator '-' and return the reformatted phone number.

Constraints:

  • 2≤2 \le number.length ≤100\le 100

  • number consists of digits and the characters '-' and ' '.

  • There are at least 22 digits in number.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Reformat Phone Number

med
30 min
Try to solve the Reformat Phone Number problem.

Statement

You are given a phone number as a string number. The string number consists of digits, spaces ' ', and dashes '-'.

Reformat the phone number by applying the following steps:

  1. Remove all spaces and dashes.

  2. Group the digits from left to right into blocks of length 33 until 44 or fewer digits remain.

  3. For the remaining digits:
    • If 22 digits remain, place them in a single block of length 22.
    • If 33 digits remain, place them in a single block of length 33.
    • If 44 digits remain, split them into two blocks of length 22 each.

Join all blocks using the separator '-' and return the reformatted phone number.

Constraints:

  • 2≤2 \le number.length ≤100\le 100

  • number consists of digits and the characters '-' and ' '.

  • There are at least 22 digits in number.