Problem · Hash Table
Shipping Cost Calculator Part 3 - Mixed Fixed/Incremental Tiers
See Stripe hiring insightsThis continues the shipping cost calculator. Now a product's tiers can each charge in one of two ways:
incremental: charge per unit, i.e.units_in_tier * cost(same as Part 2).fixed: charge a single flatcostfor the whole tier, regardless of how many units fall into it (as long as at least one unit enters the tier).
A single product can mix the two types across its tiers.
Inputs: country; items as a String[] of "product,quantity"; and rules as a String[] of "country,product,type,minQuantity,maxQuantity,cost" where type is fixed or incremental and maxQuantity = * means unbounded. Tiers use the half-open range [minQuantity, maxQuantity) with capacity maxQuantity - minQuantity. Walk tiers in order, assign min(remaining, capacity) units to each, apply the tier's pricing type, and sum across all items. Return the total integer cost.
Examples
01 · Example 1
country = "US" items = ["mouse,20", "laptop,5"] rules = ["US,mouse,incremental,0,*,550", "US,laptop,fixed,0,2,1000", "US,laptop,incremental,3,*,900", "CA,mouse,incremental,0,*,750", "CA,laptop,fixed,0,2,1100", "CA,laptop,incremental,3,*,1000"] return = 14700
US rates. mouse: 20 x 550 = 11000 (incremental). laptop (5 units): tier [0,2) is fixed -> flat 1000 for the first 2 units; tier [3,*) is incremental -> 3 x 900 = 2700; laptop total 1000 + 2700 = 3700. Grand total 11000 + 3700 = 14700.
02 · Example 2
country = "CA" items = ["mouse,20", "laptop,5"] rules = ["US,mouse,incremental,0,*,550", "US,laptop,fixed,0,2,1000", "US,laptop,incremental,3,*,900", "CA,mouse,incremental,0,*,750", "CA,laptop,fixed,0,2,1100", "CA,laptop,incremental,3,*,1000"] return = 19100
CA rates. mouse: 20 x 750 = 15000 (incremental). laptop (5 units): fixed tier [0,2) -> flat 1100; incremental tier [3,*) -> 3 x 1000 = 3000; laptop total 4100. Grand total 15000 + 4100 = 19100.
Constraints
rulesentries are"country,product,type,minQuantity,maxQuantity,cost";typeisfixedorincremental;maxQuantity = *is unbounded.- Process a product's tiers in ascending order; range is half-open
[minQuantity, maxQuantity). fixedtiers addcostonce when at least one unit enters the tier;incrementaltiers addunits * cost.- A product can mix fixed and incremental tiers.
- Return the total cost across all items as an integer.
More Stripe problems
- Account Balance Manager Part 3 - Platform CoverageONSITE INTERVIEW · Seen Jun 2026
- BitFont Part 3 - Decode Run-Length-Encoded RowsONSITE INTERVIEW · Seen Jun 2026
- Record Linkage Part 3 - Full Connected ComponentPHONE SCREEN · Seen Jun 2026
- Transaction Fee Calculator - Per-Merchant Volume DiscountPHONE SCREEN · Seen Jun 2026
- Account Balance Manager Part 2 - Reject OverdraftsONSITE INTERVIEW · Seen Jun 2026
- BitFont Part 2 - Render a WordONSITE INTERVIEW · Seen Jun 2026
- Factory Cost - Min-Cost Path Skipping One StagePHONE SCREEN · Seen Jun 2026
- HTTP Accept-Language with Quality Scores (q-factors)ONSITE INTERVIEW · Seen Jun 2026
public int calculateMixedShippingCost(String country, String[] items, String[] rules) {
// write your code here
}country"US"
items["mouse,20", "laptop,5"]
rules["US,mouse,incremental,0,*,550", "US,laptop,fixed,0,2,1000", "US,laptop,incremental,3,*,900", "CA,mouse,incremental,0,*,750", "CA,laptop,fixed,0,2,1100", "CA,laptop,incremental,3,*,1000"]
expected14700
sign in to submit