A legacy system writes fixed-width records. Parse them into dictionaries, trimming padding and skipping malformed lines.
Input schema
solve(lines: list[str], layout: list[tuple[str, int, int]]) -> list[dict]
layout entries are (field_name, start_index, length)
Example
layout = [("id", 0, 4), ("city", 4, 8)]
lines = ["0012Mumbai ", "0013Pune ", "bad"]
Output = [{"id": "0012", "city": "Mumbai"}, {"id": "0013", "city": "Pune"}]
Constraints
- A line shorter than the layout requires is malformed and skipped
- Trailing and leading spaces are stripped from every field
- Field order in the output follows the layout
- Up to 10,000,000 lines
Community-reported interview topic. Not an official company question and no affiliation is implied.