FastPrepSouvenir Shop Purchases
Problems/Souvenir Shop Purchases

Souvenir Shop Purchases

Amazon logoAmazon● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamples

Problem statement

In an Amazon Souvenir Shop, a shopper visited a souvenir shop with items arranged on the shelf from left to right. The goal is to purchase as many items as possible within a given budget. Notably, the cost of each souvenir increases with each purchase.

Formally, given an array cost of size n, representing the initial cost of each item in the souvenir shop, and m representing the initial amount of money that the shopper has.

The first time a souvenir is bought its cost will be cost[i], the second time it will be 2 * cost[i], the third time it will be 3 * cost[i], and the jth time it will cost j * cost[i], and so on.

The shopper will buy items one by one from left to right, and when she reaches the last item she will go back to the start and repeat this operation until she runs out of money.

What is the number of items that the shopper will buy before she runs out of money?

Function

countPurchasedItems(cost: int[], m: long) → long

Examples

Example 1

cost = [2, 5, 1, 1]m = 18return = 5

Assuming 1-based indexing of the cost array:

  1. Buy item 1 for 2. Remaining money: 18 - 2 = 16. New costs: [4, 5, 1, 1].
  2. Buy item 2 for 5. Remaining money: 16 - 5 = 11. New costs: [4, 10, 1, 1].
  3. Buy item 3 for 1. Remaining money: 11 - 1 = 10. New costs: [4, 10, 2, 1].
  4. Buy item 4 for 1. Remaining money: 10 - 1 = 9. New costs: [4, 10, 2, 2].
  5. Buy item 1 for 4. Remaining money: 9 - 4 = 5. New costs: [6, 10, 2, 2].

The next item would be item 2, which now costs 10, but only 5 money remains. Therefore, the shopper buys 5 items.

More Amazon Online Assessment questions

  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Nov 2026
  • Minimum Merge ConflictsOA · Seen Nov 2026
  • Shopping Cart BillingOA · Seen Nov 2026

Similar questions at other companies

  • Capping Portfolio WeightsCapstone Investment Advisors · OA
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
  • Index of the Maximum After Left RotationsChubb · OAChubb interview questions
  • Rolling MetricsAkuna Capital · OAAkuna Capital interview questions
  • Macaron Order PriceOpenAI · OAOpenAI interview questions
  • Daily Settlement for Long and Short PositionsBelvedere Trading · OA
  • Maximum Alloy Production Within BudgetMicrosoft · OAMicrosoft interview questions
  • Forward Block Placement QueriesCapital One · OACapital One interview questions
  • Linear InterpolatorTwo Sigma · OATwo Sigma interview questions

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights
Saved
class Solution {
    public long countPurchasedItems(int[] cost, long m) {
      // write your code here
    }

}
Checking account…