Tap here to switch tabs
Problem
Submissions

Problem: Masking Personal Information

med
30 min
Try to solve the Masking Personal Information problem.

Statement

You are given a personal information string s, which represents either an email address or a phone number. Return the masked personal information according to the following rules:

Email address:

An email address consists of a local name, an '@' symbol, and a domain name. To mask an email:

  1. Convert all uppercase letters in both the local name and the domain name to lowercase.

  2. Replace all characters between the first and last character of the local name with 55 asterisks "*****".

Phone number:

A phone number consists of 1010 to 1313 digits, separated by possible formatting characters such as spaces, '(', ')', '-', and '+'. The last 1010 digits always form the local phone number, and any digits before them form the country code (ranging from 00 to 33 digits). To mask a phone number:

  1. Remove all separation characters, keeping only the digits.

  2. The local number is masked as "***-***-XXXX", where "XXXX" represents the last 44 digits of the original phone number.

  3. If a country code is present (11, 22, or 33 digits), prepend "+*-", "+**-", or "+***-" respectively to the masked local number.

Constraints:

  • s is either a valid email address or a phone number.

  • If s is an email:

    • 8≤8 \leq s.length ≤40\leq 40

    • s consists of uppercase and lowercase English letters, exactly one '@' symbol, and exactly one '.' symbol.

  • If s is a phone number:

    • 10≤10 \leq s.length ≤20\leq 20

    • s consists of digits, spaces, and the symbols '(', ')', '-', and '+'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Masking Personal Information

med
30 min
Try to solve the Masking Personal Information problem.

Statement

You are given a personal information string s, which represents either an email address or a phone number. Return the masked personal information according to the following rules:

Email address:

An email address consists of a local name, an '@' symbol, and a domain name. To mask an email:

  1. Convert all uppercase letters in both the local name and the domain name to lowercase.

  2. Replace all characters between the first and last character of the local name with 55 asterisks "*****".

Phone number:

A phone number consists of 1010 to 1313 digits, separated by possible formatting characters such as spaces, '(', ')', '-', and '+'. The last 1010 digits always form the local phone number, and any digits before them form the country code (ranging from 00 to 33 digits). To mask a phone number:

  1. Remove all separation characters, keeping only the digits.

  2. The local number is masked as "***-***-XXXX", where "XXXX" represents the last 44 digits of the original phone number.

  3. If a country code is present (11, 22, or 33 digits), prepend "+*-", "+**-", or "+***-" respectively to the masked local number.

Constraints:

  • s is either a valid email address or a phone number.

  • If s is an email:

    • 8≤8 \leq s.length ≤40\leq 40

    • s consists of uppercase and lowercase English letters, exactly one '@' symbol, and exactly one '.' symbol.

  • If s is a phone number:

    • 10≤10 \leq s.length ≤20\leq 20

    • s consists of digits, spaces, and the symbols '(', ')', '-', and '+'.