Macaron Order Price
Updated
Problem statement
A baker sells macarons with at most five distinct flavors. Every macaron has the same unit price. You are given quantities, where quantities[i] is the number of macarons of the i-th distinct flavor in an order, and an integer unitPrice in whole currency units.
The baker packs the order into sets. Each set contains at most five macarons and at most one macaron of any flavor. To fill each set as much as possible, the baker repeatedly takes one macaron from every flavor that still has a positive quantity, then starts the next set. The order of flavors within a set and the order of the completed sets do not matter.
Each set receives a discount based on its number of distinct flavors:
- One flavor: no discount.
- Two flavors:
10%off the price of the set. - Three flavors:
20%off the price of the set. - Four flavors:
30%off the price of the set. - Five flavors:
40%off the price of the set.
The undiscounted price of a set is its number of macarons multiplied by unitPrice. Return the total discounted order price as an integer number of hundredths of a currency unit. For example, a price of 14 currency units is returned as 1400. No rounding is needed.
Function
macaronOrderPrice(quantities: int[], unitPrice: int) → longExamples
Example 1
quantities = [2,2,1,1,1]unitPrice = 10return = 4800The first set has five flavors and costs 5 × 10 × 0.6 = 30 currency units. The second has two flavors and costs 2 × 10 × 0.9 = 18. The total is 48 units, so return 4800.
Example 2
quantities = [3,0,0]unitPrice = 2return = 600Only one flavor is present, so the baker makes three single-macaron sets. There is no discount: 3 × 2 = 6 currency units, or 600 hundredths.
Example 3
quantities = [3,1,2,0,2]unitPrice = 4return = 2480The set sizes are 4, 3, and 1. Their prices are 11.2, 9.6, and 4 currency units. The total is 24.8 units, so return 2480.
Constraints
1 <= quantities.length <= 5.0 <= quantities[i] <= 10^6.- At least one entry in
quantitiesis positive. 1 <= unitPrice <= 10^4.- The returned price fits in a signed
64-bit integer.
More OpenAI Online Assessment questions
- Count Routes Through Four Shop TypesOA · Seen Oct 2026
- Digit-Sum Sequence Join PointOA · Seen Oct 2026
- Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026
- Password Clues and the Next CommandOA · Seen Oct 2026
- Longest Increasing Price SubsequenceOA · Seen Oct 2026
- Shortest Atom Action PathOA · Seen Oct 2026
- Simplify a Quadratic ExpressionOA · Seen Oct 2026
- Minimum-Cost Color SequenceOA · PHONE SCREEN · Seen Oct 2026
- Largest Microorganism After ConsumptionOA · Seen Oct 2026
- Invert or Blur an ImageOA · Seen Sep 2026
Similar questions at other companies
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Beam Search and Nucleus DecodingMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Daily Settlement for Long and Short PositionsBelvedere Trading · OA
- Sorted Cyclic Shift Difference SumsCapital One · OACapital One interview questions
- Optimize Package Order by Sorting One WindowAmazon · OA
- Linear InterpolatorTwo Sigma · OATwo Sigma interview questions