FastPrepMaximum Purchases with a Cooler-Bag Fee
Problems/Maximum Purchases with a Cooler-Bag Fee

Maximum Purchases with a Cooler-Bag Fee

Infosys logoInfosys● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Infosys new grad online assessment. The report defines item costs and types, a one-time cost for the cooler, that each item is used once, the budget, and the goal of the largest count. We added limits on the numbers and a function signature. Our version is about 98% the same as the reported exercise.

Each item has a positive cost in costs and a type in types: 0 or 1. You may buy each item at most once without exceeding budget.

If you buy at least one type-1 item, you must also pay coolerCost exactly once. Buying only type-0 items does not require that fee.

Return the maximum number of items you can buy.

Function

maxPurchasableItems(costs: int[], types: int[], budget: long, coolerCost: int) → int

Examples

Example 1

costs = [4,2,7,1]types = [0,1,1,0]budget = 10coolerCost = 3return = 3

Items costing 1, 2, and 4 plus the one-time fee cost exactly 10.

Example 2

costs = [2,3,4]types = [0,0,1]budget = 5coolerCost = 5return = 2

The two type-0 items fit exactly, while any type-1 purchase requires more than the budget.

Constraints

  • 1 <= costs.length == types.length <= 200000
  • 1 <= costs[i] <= 1000000000
  • types[i] is 0 or 1.
  • 0 <= budget <= 10^18
  • 0 <= coolerCost <= 1000000000

More Infosys Online Assessment questions

  • At Most K Jumps with Quadratic Transition CostOA · Seen Nov 2026
  • Hiking Club Fastest PaceOA · Seen Nov 2026
  • Lowest Common Ancestor with a Changing RootOA · Seen Nov 2026
  • Minimum Leaf Path Sum over All RootsOA · Seen Nov 2026
  • Split Array to Minimize the Largest SumOA · Seen Nov 2026
  • Cherry PickupOA · Seen Nov 2026
  • Lexicographically Smallest Grid Path with One Letter ChangeOA · Seen Nov 2026
  • Minimum Cost to Supply Water with Wells and PipesOA · Seen Nov 2026
  • Minimum Cost to Tile a Strip with Widths 1, 2, and 3OA · Seen Nov 2026
  • Minimum Rounds to Complete All TasksOA · Seen Nov 2026

Similar questions at other companies

  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
  • Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
  • Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions
  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
  • Maximize Center A Package BenefitAmazon · OA
  • EV Charging Cost OptimizationTata Consultancy Services · OATata Consultancy Services interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
All Infosys interview questionsSee Infosys hiring insights
Saved
class Solution {
    public int maxPurchasableItems(int[] costs, int[] types, long budget, int coolerCost) {
        // Write your code here.
    }
}
Checking account…