InterviewDB Experience · USA

Date Format: Parse and Normalize Dates Across Multiple Input Formats

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

  1. How do you distinguish MM/DD/YYYY from DD/MM/YYYY when the day is <= 12?
  2. How would you handle two-digit years (e.g., "01/15/23") — what century assumption is safe?
  3. Extend to also normalize time zones: inputs may include "Jan 15 2023 10:00 EST".
  4. 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

  1. How do you distinguish MM/DD/YYYY from DD/MM/YYYY when the day is <= 12?
  2. How would you handle two-digit years (e.g., "01/15/23") — what century assumption is safe?
  3. Extend to also normalize time zones: inputs may include "Jan 15 2023 10:00 EST".
  4. How would you make this function production-grade — what edge cases and locales must you test?

About This Question

This is a candidate experience report from a faire interview during the onsite round.

It covers the following topics: Coding, Strings, Onsite .