FastPrepMacaron Order with Set Discounts
Problems/Macaron Order with Set Discounts

Macaron Order with Set Discounts

Shopify logoShopify● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Shopify online assessment for a software engineering internship, taken between July and September 2026. It was the third of three coding tasks, followed by an aptitude quiz.

The report gives the pricing rules: one price for every macaron, at most five flavors, sets that never hold more than five macarons or two of one flavor and that the baker fills as far as possible, 10% to 40% off for sets of two to five flavors, and a total rounded down to a whole number. It shows three worked prices but not the orders behind them, and it does not say how the order is passed in. So we chose a list with one flavor label per macaron, wrote orders that give those three prices, and chose a whole-number unit price and the limits ourselves.

Our version is about 90% the same as the reported question.

A bakery sells macarons. Every macaron costs the same whole-number price unitPrice and comes in one flavor. You are given an order as the array macarons, where macarons[i] is the flavor label of one macaron. Equal labels mean the same flavor, and an order has at most five flavors.

The order is split into sets. A set holds at most five macarons, and no two macarons in a set have the same flavor. The baker makes every set as big as it can be: a new set gets one macaron of each flavor that has macarons left, and the next set starts once that is done. This repeats until no macarons are left.

Before the discount, a set costs its number of macarons times unitPrice. The discount depends on how many flavors the set has:

  • 1 flavor: no discount.
  • 2 flavors: 10% off.
  • 3 flavors: 20% off.
  • 4 flavors: 30% off.
  • 5 flavors: 40% off.

Return the total price of the order after the discounts, rounded down to a whole number. Only the final total is rounded, not the price of each set.

Function

computeTotalPrice(unitPrice: int, macarons: String[]) → int

Examples

Example 1

unitPrice = 1macarons = ["vanilla","pistachio","rose","lemon","chocolate","vanilla"]return = 4

There are five flavors, and vanilla appears twice. The first set takes one macaron of each flavor: five flavors, so 40% off, and it costs 5 × 1 × 0.6 = 3. The second vanilla goes alone into a second set with no discount, costing 1. The total is 3 + 1 = 4.

Example 2

unitPrice = 4macarons = ["lemon","rose","rose","lemon"]return = 14

Two flavors with two macarons each make two sets of lemon and rose. Each set has two flavors, so 10% off: 2 × 4 × 0.9 = 7.2. The total is 7.2 + 7.2 = 14.4, which rounds down to 14.

Example 3

unitPrice = 4macarons = ["mint","lemon","mint","rose"]return = 13

The first set takes mint, lemon and rose: three flavors, so 20% off, costing 3 × 4 × 0.8 = 9.6. The second mint goes alone and costs 4. The total is 13.6, which rounds down to 13.

Example 4

unitPrice = 7macarons = ["plum","rose","mint","lemon","rose","mint","plum"]return = 36

The first set takes one of each of the four flavors, so it gets 30% off: 4 × 7 × 0.7 = 19.6. The second set takes the remaining rose, mint and plum, with 20% off: 3 × 7 × 0.8 = 16.8. The total is 36.4, so the answer is 36. Rounding each set down first would give 19 + 16 = 35, which is wrong: only the total is rounded.

Constraints

  • 1 <= unitPrice <= 10^4
  • 1 <= macarons.length <= 10^4
  • 1 <= macarons[i].length <= 10
  • macarons[i] consists of lowercase English letters.
  • macarons has no more than 5 different labels.

More Shopify Online Assessment questions

  • Card Game: Best First-Player ScoreOA · Seen Nov 2026
  • Polynomial CoefficientsOA · Seen Nov 2026
  • Choose Items for a BackpackOA · Seen May 2026
  • Filter Words Containing a LetterOA · Seen Aug 2025
  • Paint HouseOA · Seen Aug 2025
  • Longest Increasing SubsequenceOA · Seen May 2025
  • Find the Compromised ServerOA · Seen Apr 2025
  • Fix the First Robot InstructionOA · Seen Dec 2024
  • Validate a Directed GraphOA · Seen Mar 2018
  • Min StackOA

Similar questions at other companies

  • Parcel Attribute Store with TTLAirbnb · OAAirbnb interview questions
  • HTTP Request RedirectionAmazon · OA
  • Aggregate Paginated Project Run RecordsReplit · OA
  • AI Role: Collection with Add and Remove OperationsApple · PHONE SCREENApple interview questions
  • Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
  • Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions
  • Read a File from Distributed ChunksHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions
  • Popular and Instant-Runoff Election WinnersCoursera · PHONE SCREEN
  • P&L Leaderboard OperationsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Schedule Invoice Emails and DelinquenciesStripe · ONSITE INTERVIEWStripe interview questions

Shopify interview experiences

  • Shopify AI Pair Programming Interview: 2 Experiences
  • Shopify Intern Older Life Story: 19 Experiences (Part 4 of 4)
  • Shopify Intern Life Story and OA: 20 Experiences (Part 3 of 4)
  • Shopify Intern OOP Pairing: 20 Experiences (Part 2 of 4)
  • Shopify SWE Intern Interviews: 79 Experiences (Part 1 of 4)
All Shopify interview questionsSee Shopify hiring insights
Saved
class Solution {
    public int computeTotalPrice(int unitPrice, String[] macarons) {
        // Write your code here.
    }
}
Checking account…