Masking Personal Information
To mask the personal information according to the given rules, we can differentiate between email addresses and phone numbers based on the characters in the given string s
. We’ll write separate functions for masking emails and phone numbers and apply them accordingly.
Python solution:
|
|
Explanation:
- If
s
contains an ‘@’, we consider it an email address and call themaskEmail
function. Otherwise, we call themaskPhone
function. maskEmail
splits the email into two parts, the name and the domain, then constructs the masked email as described in the problem.maskPhone
filters out the digits from the phone number, constructs the local number, and then adds the country code, if present, using the given formatting rules.
The code ensures that the masking is performed according to the constraints, following the given examples.