Code RoomMask email addresses in logs
MediumPrep Room Coding #161

Mask email addresses in logs

CodingSecurityMid–Senior~20 min

Mask email addresses in a log line to avoid leaking PII. Given a `text` string, replace every email address with a masked form that keeps the first character of the local part, replaces the rest of the local part with '*' (one star per hidden character), and leaves the '@domain' intact. An email is a run matching local@domain.tld where local is [A-Za-z0-9._%+-]+, domain is [A-Za-z0-9.-]+, and tld is at least 2 letters. If the local part is a single character, mask it entirely. Text with no emails is returned unchanged.

Implement
mask_emails(text: str) → str
Examples
in["Contact alice@example.com now"]out"Contact a****@example.com now"
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 20 min
InputExpectedGot
["Contact alice@example.com now"]"Contact a****@example.com now"not run yetsample