Calculate a Basket Total from Delimited Product Records
Company: Instacart
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Implement `total_price_cents(items)` for a list of product records. Each record has exactly this format:
```text
sku|product name|quantity|unit price in cents
```
Return the sum of `quantity * unit price in cents` across all records, as an exact integer number of cents represented by a decimal string as described below. For this interface, quantities are whole nonnegative units and prices are nonnegative integer cents. Records are well formed, and fields do not contain the separator character.
Each record contributes independently, including records with the same SKU. An empty list has total zero. No discounts, taxes, or rounding are part of this function.
### Exact result representation
The input records remain strings in the format above. Return the exact total as a canonical nonnegative decimal string: `"0"` or a sequence of ASCII digits beginning with `1` through `9`, with no sign, leading zeroes, or whitespace.
This output representation preserves integer-cent totals of any magnitude. It does not impose a monetary bound or change the arithmetic. Do not round, overflow a fixed-width type, or return a remainder modulo another number. An empty list returns `"0"`.
### Examples
```text
total_price_cents(["a100|Apple|2|125", "b200|Bread|1|350"])
-> "600"
```
The records contribute 250 cents and 350 cents.
```text
total_price_cents(["a100|Apple|1|125", "a100|Apple|3|125", "c300|Cup|0|400"])
-> "500"
```
Both apple records contribute, and a zero-quantity record contributes zero. Use integer arithmetic to preserve the input's cent-based representation. No maximum list size or monetary bound is specified.
Overview: Parse SKU, product, quantity, and integer-cent prices to calculate a basket total, with repeated records, zero quantities, and exact integer arithmetic.
Read the full Instacart Software Engineer interview experience this question came from
Implement `total_price_cents(items)` for a list of product records. Each record has exactly this format:
```text
sku|product name|quantity|unit price in cents
```
Return the sum of `quantity * unit price in cents` across all records, as an exact integer number of cents represented by a decimal string as described below. For this interface, quantities are whole nonnegative units and prices are nonnegative integer cents. Records are well formed, and fields do not contain the separator character.
Each record contributes independently, including records with the same SKU. An empty list has total zero. No discounts, taxes, or rounding are part of this function.
### Exact result representation
The input records remain strings in the format above. Return the exact total as a canonical nonnegative decimal string: `"0"` or a sequence of ASCII digits beginning with `1` through `9`, with no sign, leading zeroes, or whitespace.
This output representation preserves integer-cent totals of any magnitude. It does not impose a monetary bound or change the arithmetic. Do not round, overflow a fixed-width type, or return a remainder modulo another number. An empty list returns `"0"`.
### Examples
```text
total_price_cents(["a100|Apple|2|125", "b200|Bread|1|350"])
-> "600"
```
The records contribute 250 cents and 350 cents.
```text
total_price_cents(["a100|Apple|1|125", "a100|Apple|3|125", "c300|Cup|0|400"])
-> "500"
```
Both apple records contribute, and a zero-quantity record contributes zero. Use integer arithmetic to preserve the input's cent-based representation. No maximum list size or monetary bound is specified.
Constraints
- Each input is a well-formed sku|product name|quantity|unit price in cents record with no pipe inside a field.
- Quantities and unit-cent prices are nonnegative integers; the original record input format is unchanged.
- Every record contributes independently, including repeated SKUs.
- Return the exact sum as a canonical nonnegative decimal string; empty input returns "0".
- No monetary/list-size bound, discounts, taxes or rounding are introduced; canonical spelling is an output requirement.
Examples
Input: (['a100|Apple|2|125', 'b200|Bread|1|350'],)
Expected Output: '600'
Explanation: The first source example contributes 250 plus 350 cents.
Input: (['a100|Apple|1|125', 'a100|Apple|3|125', 'c300|Cup|0|400'],)
Expected Output: '500'
Explanation: The second source example preserves repeated SKU contributions and zero quantity.
Hints
- The last field is already measured in cents.
- Repeated SKUs still represent independent record contributions.