bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 831. Masking Personal Information

831. Masking Personal Information

Leetcode Solutions

Masking Personal Information

  1. Check if the input string contains an '@' symbol to determine if it is an email.
  2. If it is an email, split the string into name and domain using the '@' symbol.
  3. Convert the entire email to lowercase.
  4. Mask the name by keeping the first and last character and replacing the middle characters with five asterisks.
  5. Concatenate the masked name, '@', and domain to form the masked email.
  6. If it is a phone number, remove all non-digit characters.
  7. Determine the length of the country code by subtracting 10 from the total length of digits.
  8. Mask the last 10 digits as '--XXXX'.
  9. Prepend the country code mask based on its length (0, 1, 2, or 3 digits).
  10. Return the masked phone number.
UML Thumbnail

Regex-based Masking of Personal Information

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...