Skip to content

Practice Masking Personal Information

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#831
LeetCode Problem

Masking Personal Information

Problem Statement

Mask s, which is a valid email address or phone number. For an email, lowercase the whole address and replace all letters between the first and last letters of the name before @ with exactly five asterisks; keep the domain. An email name has at least two letters. For a phone number, discard separators +, -, parentheses and spaces. There are 10 through 13 digits: the last ten form the local number and any earlier digits form its country code. Keep only the last four digits. With no country code, return ***-***-XXXX. With one, two or three country-code digits, prepend +*-, +**- or +***- respectively to that local masked form.

Source: Masking Personal Information on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "LeetCode@LeetCode.com"
Output
"l*****e@leetcode.com"

# Example 2

Input
s = "AB@qq.com"
Output
"a*****b@qq.com"

# Example 3

Input
s = "1(234)567-890"
Output
"***-***-7890"

Constraints

s is either a valid email or a phone number.
If s is an email: 8 <= s.length <= 40 s consists of uppercase and lowercase English letters and exactly one '@' symbol and '.' symbol.
8 <= s.length <= 40
s consists of uppercase and lowercase English letters and exactly one '@' symbol and '.' symbol.
If s is a phone number: 10 <= s.length <= 20 s consists of digits, spaces, and the symbols '(', ')', '-', and '+'.
10 <= s.length <= 20
s consists of digits, spaces, and the symbols '(', ')', '-', and '+'.

Related LeetCode Problems

Practice more problems similar to Masking Personal Information.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.