InterviewDB
Experience
·
USA
Date Format: Parse and Normalize Dates Across Multiple Input Formats
Onsite
Interview Experience
Problem
You are given a list of date strings in various formats. Normalize them all to YYYY-MM-DD. Supported input formats include: MM/DD/YYYY, DD-MM-YYYY, Month DD, YYYY (e.g., "January 5, 2023"), and ISO YYYY-MM-DD.
Return None for unparseable strings.
python
def normalize_date(date_str: str) -> str | None:
pass
def batch_normalize(dates: list[str]) -> list[str | None]:
pass
**Input**: ["01/15/2023", "15-01-2023", "January 15, 2023", "2023-01-15", "bad input"]
**Output**: ["2023-01-15", "2023-01-15", "2023-01-15", "2023-01-15", None]
Follow-ups
- How do you distinguish
MM/DD/YYYYfromDD/MM/YYYYwhen the day is <= 12? - How would you handle two-digit years (e.g.,
"01/15/23") — what century assumption is safe? - Extend to also normalize time zones: inputs may include
"Jan 15 2023 10:00 EST". - How would you make this function production-grade — what edge cases and locales must you test?
Full Details
Problem
You are given a list of date strings in various formats. Normalize them all to YYYY-MM-DD. Supported input formats include: MM/DD/YYYY, DD-MM-YYYY, Month DD, YYYY (e.g., "January 5, 2023"), and ISO YYYY-MM-DD.
Return None for unparseable strings.
python
def normalize_date(date_str: str) -> str | None:
pass
def batch_normalize(dates: list[str]) -> list[str | None]:
pass
**Input**: ["01/15/2023", "15-01-2023", "January 15, 2023", "2023-01-15", "bad input"]
**Output**: ["2023-01-15", "2023-01-15", "2023-01-15", "2023-01-15", None]
Follow-ups
- How do you distinguish
MM/DD/YYYYfromDD/MM/YYYYwhen the day is <= 12? - How would you handle two-digit years (e.g.,
"01/15/23") — what century assumption is safe? - Extend to also normalize time zones: inputs may include
"Jan 15 2023 10:00 EST". - How would you make this function production-grade — what edge cases and locales must you test?
Free preview. Unlock all Faire questions →
About This Question
This is a candidate experience report from a faire interview during the onsite round.
More Faire Interview Questions
InterviewDB
Ads Filter: Remove Advertisements from a List Based on Heuristics
InterviewDB
Funnel Count: Compute Drop-Off at Each Step of a Conversion Funnel
InterviewDB
Haiku Substring: Find Substrings Matching a 5-7-5 Syllable Pattern
InterviewDB
Split SMS: Break a Long Message into Valid SMS Segments
InterviewDB
Faire SWE Onsite - Tag Validation (Stack/Parsing)