Basic Item Discounts
Updated
Problem statement
You are given a shopping cart and a set of item-specific percentage discounts. Item prices are expressed in integer cents.
For every item, apply the discount whose name matches the item's name. A discount applies to every cart item with that name. Ignore discounts whose names do not match any item.
Compute and return a three-element array containing:
- the subtotal, which is the sum of all original prices;
- the total discount, which is the sum of the rounded discount amounts; and
- the final total, which is the subtotal minus the total discount.
For each item, compute price * percentOff / 100 without intermediate rounding, then round the final discount to the nearest cent. An exact half-cent tie rounds to the nearest even integer, matching Python round().
Function
calculateItemDiscountTotals(itemNames: String[], prices: int[], discountNames: String[], percentOff: int[]) → long[]Examples
Example 1
itemNames = ["Milk", "Bread"]prices = [500, 300]discountNames = ["Milk"]percentOff = [10]return = [800, 50, 750]The subtotal is 800 cents. Milk receives a 50-cent discount, while Bread has no matching discount.
Example 2
itemNames = ["A", "B"]prices = [105, 115]discountNames = ["A", "B"]percentOff = [10, 10]return = [220, 22, 198]The raw discounts are 10.5 and 11.5 cents. Ties-to-even rounding produces 10 and 12 cents.
Example 3
itemNames = ["Apple"]prices = [399]discountNames = ["Orange"]percentOff = [25]return = [399, 0, 399]The only discount is unmatched, so it is ignored.
Constraints
1 ≤ itemNames.length = prices.length ≤ 100000.0 ≤ discountNames.length = percentOff.length ≤ 100000.0 ≤ prices[i] ≤ 10^9.0 ≤ percentOff[i] ≤ 100.- Item and discount names are non-empty case-sensitive strings.
- There is at most one discount for each discount name.
- The subtotal and returned totals fit in a signed 64-bit integer.
More Palantir Online Assessment questions
- Optimize Discount Selection Under a Point BudgetOA · Seen Nov 2026
- Stacked Item and Category DiscountsOA · Seen Nov 2026
- Minimize Path ValueOA · Seen Sep 2024
- No Pairs AllowedOA · Seen Sep 2024
- REST API: Country CodesOA · Seen Feb 2024
- Swap ParityOA · Seen Feb 2024
- Freelance Candidate ReviewOA · Seen Nov 2023
- Benchmarking Tool ReportOA · Seen Sep 2023
- Count Fit Records Across PagesOA · Seen Sep 2023
- Network FormationOA · Seen Sep 2023
Similar questions at other companies
- Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW
- Count Valid Square PairsAuxoAI · OA
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- Costliest ChocolateRippling · OARippling interview questions
- Distinct Products After Removing One ElementHSBC · OAHSBC interview questions
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Plus Mult ArrayIBM · OAIBM interview questions
- Progressive Tax CalculatorInteractive Brokers · OA
- 2020 Account Balance with Monthly Card FeesDRW · OADRW interview questions
- Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
Interview reports that mention this question
Palantir interview experiences
- Palantir FDSE Experienced-Hire Interviews: 5 Experiences
- Palantir FDSE New Grad OA Questions: 6 Experiences (Part 2 of 2)
- Palantir FDSE New Grad Interviews: 5 Experiences (Part 1 of 2)
- Palantir FDSE Karat and Learning: 7 Experiences (Part 2 of 2)
- Palantir FDSE OA and Interviews: 16 Experiences (Part 1 of 2)