Normalize Retailer Package Size Strings Into Standard Units
Last updated: November 29, 2026
Quick Overview
Retailer catalog feeds describe sizes as free text like '2 x 16 oz', '1.5L' or '12 ct'. Write a function that parses one string into a total amount in grams, milliliters or count, returning None for anything it cannot parse.
Instacart
November 29, 20260
0
0 solved
Retailer catalog feeds describe sizes as free text like '2 x 16 oz', '1.5L' or '12 ct'. Write a function that parses one string into a total amount in grams, milliliters or count, returning None for anything it cannot parse.
Instacart ingests catalogs from many retailers in inconsistent formats, and price-per-unit comparisons depend on clean sizes. This screen checks careful string parsing, explicit unit tables and honest handling of unparseable input rather than guessing.
What the Interviewer Expects
- Lowercase and trim input before matching
- Support an optional multipack prefix such as '6 x'
- Handle decimals and simple fractions like 1/2 lb
- Keep units in lookup tables so adding a unit is a data change
- Return None for unknown units instead of guessing
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you tell weight ounces apart from fluid ounces when the feed just says 'oz'?
- How would you measure parser coverage across a whole retailer feed?
- Where would you store parse failures so the catalog team can fix them?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: one size string. Output: (amount, unit) where unit is g, ml or ct, or None. Examples to confirm with the interviewer: 2 x 16 oz is 32 ounces, 1.5L is 1500 ml, 12 ct is 12, `1/2 lb...
High-Level Design
One anchored regex with three groups: optional pack count followed by x, the amount as a fraction or decimal, and a unit word. Then look the unit up in a mass table or a volume table. Plain oz is ...