Masking Personal Information - Problem
Masking Personal Information is a common privacy protection technique used in data processing systems. You're given a personal information string
๐ง Email Masking Rules:
โข Convert all letters to lowercase
โข Keep only the first and last letter of the name part (before @)
โข Replace middle letters with exactly 5 asterisks "*****"
โข Example:
๐ฑ Phone Number Masking Rules:
โข Remove all separators:
โข Last 10 digits are the local number, remaining 0-3 digits are country code
โข Format based on country code length:
- 0 digits:
- 1 digit:
- 2 digits:
- 3 digits:
โข XXXX represents the last 4 digits of the local number
s that represents either an email address or a phone number. Your task is to return the properly masked version following specific rules.๐ง Email Masking Rules:
โข Convert all letters to lowercase
โข Keep only the first and last letter of the name part (before @)
โข Replace middle letters with exactly 5 asterisks "*****"
โข Example:
"John@Example.com" โ "j*****n@example.com"๐ฑ Phone Number Masking Rules:
โข Remove all separators:
+, -, (, ), spaceโข Last 10 digits are the local number, remaining 0-3 digits are country code
โข Format based on country code length:
- 0 digits:
"***-***-XXXX"- 1 digit:
"+*-***-***-XXXX"- 2 digits:
"+**-***-***-XXXX"- 3 digits:
"+***-***-***-XXXX"โข XXXX represents the last 4 digits of the local number
Input & Output
example_1.py โ Email Masking
$
Input:
s = "LeetCode@LeetCode.com"
โบ
Output:
"l*****e@leetcode.com"
๐ก Note:
The email name 'LeetCode' becomes 'l*****e' (first + 5 asterisks + last), and everything is converted to lowercase
example_2.py โ Domestic Phone
$
Input:
s = "1(234)567-890"
โบ
Output:
"***-***-7890"
๐ก Note:
After removing separators we get '1234567890' (10 digits), so no country code. Format is '***-***-XXXX' where XXXX is '7890'
example_3.py โ International Phone
$
Input:
s = "86-(10)12345678"
โบ
Output:
"+**-***-***-5678"
๐ก Note:
After removing separators we get '861012345678' (12 digits), so 2-digit country code '86'. Format is '+**-***-***-XXXX'
Constraints
- 1 โค s.length โค 40
- s is either a valid email or a phone number
- If s is an email: name and domain contain only letters, domain has exactly one '.' separator
- If s is a phone number: it contains 10-13 digits total
Visualization
Tap to expand
Understanding the Visualization
1
Document Scanning
Scanner detects '@' symbol to classify as email vs phone number
2
Email Protocol
Apply email masking: convert to lowercase, keep first/last of name, mask middle with 5 stars
3
Phone Protocol
Apply phone masking: extract digits, determine country code length, format accordingly
4
Output Generation
Return properly masked result following privacy standards
Key Takeaway
๐ฏ Key Insight: Pattern recognition allows instant classification - emails have '@' symbols, phones are pure digits after separator removal, enabling efficient single-pass processing with appropriate masking protocols.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code