Maximum Purchases with a Cooler-Bag Fee
Updated
Problem statement
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) → intExamples
Example 1
costs = [4,2,7,1]types = [0,1,1,0]budget = 10coolerCost = 3return = 3Items 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 = 2The two type-0 items fit exactly, while any type-1 purchase requires more than the budget.
Constraints
1 <= costs.length == types.length <= 2000001 <= costs[i] <= 1000000000types[i]is 0 or 1.0 <= budget <= 10^180 <= 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