Column Type: Infer and Validate the Data Type of Each Column in a CSV-like Table
Interview Experience
Problem
Given a table as a list of rows (each row is a list of string values), infer the most specific data type for each column. Types in priority order: int > float > date (YYYY-MM-DD) > boolean (true/false) > string. A column's type is the most specific type that all non-empty values in that column can be parsed as.
python
def infer_column_types(rows: list[list[str]]) -> list[str]:
pass
Example:
rows = [
["1", "3.14", "2023-01-01", "true", "hello"],
["2", "2.71", "2023-06-15", "false", "world"],
["abc", "1.0", "not-a-date", "true", "!"],
]
**output** -> ["string", "float", "string", "boolean", "string"]
Follow-ups
1. Empty cells -- should they be treated as missing (skip for type inference) or as the string ""?
2. Dates appear in multiple formats (MM/DD/YYYY, DD-MM-YYYY). How do you handle ambiguous formats?
3. A column is 99% integers but has one outlier string. What threshold would you use to decide the type?
4. Extend to also return nullable status: a column is nullable if any cell is empty.
Full Details
Problem
Given a table as a list of rows (each row is a list of string values), infer the most specific data type for each column. Types in priority order: int > float > date (YYYY-MM-DD) > boolean (true/false) > string. A column's type is the most specific type that all non-empty values in that column can be parsed as.
python
def infer_column_types(rows: list[list[str]]) -> list[str]:
pass
Example:
rows = [
["1", "3.14", "2023-01-01", "true", "hello"],
["2", "2.71", "2023-06-15", "false", "world"],
["abc", "1.0", "not-a-date", "true", "!"],
]
**output** -> ["string", "float", "string", "boolean", "string"]
Follow-ups
1. Empty cells -- should they be treated as missing (skip for type inference) or as the string ""?
2. Dates appear in multiple formats (MM/DD/YYYY, DD-MM-YYYY). How do you handle ambiguous formats?
3. A column is 99% integers but has one outlier string. What threshold would you use to decide the type?
4. Extend to also return nullable status: a column is nullable if any cell is empty.
About This Question
This is a candidate experience report from a airtable interview during the phone round.
It covers the following topics: Coding, Phone, Onsite, Strings .