Reported September 2026
Salesforcegreedy

Maximize Monsters Defeated

Reported by candidates from Salesforce's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Salesforce OA. Under 2s to a working solution.
Founder's read

Salesforce reported this one in September 2026, and it looks fancier than it is. Strip the monster theme and it's a pick-the-cheapest-items problem with a hard cap on how many you can take. Two budgets, bullets and poison doses, but the poison dose just limits the count. If you've got the OA invite and 48 hours, this is a sorting-plus-greedy question you can nail in under 10 lines. StealthCoder sits invisibly on your screen as a safety net if you blank during the live assessment, but the idea here is simple enough to hold in your head.

The problem

Defeating monster i consumes bulletRequirements[i] bullets and one poison dose. Each monster may be defeated at most once.
Given the available bullets and poison doses, return the maximum number of monsters that can be defeated.

Function
maximizeMonstersDefeated(bulletRequirements: int[], availableBullets: int, poisonDoses: int) → int

Examples
Example 1
bulletRequirements = [4,2,7,1]
availableBullets = 7
poisonDoses = 3
return = 3
Case 1 exercises the documented deterministic contract.
Example 2
bulletRequirements = [5,6]
availableBullets = 20
poisonDoses = 1
return = 1
Case 2 exercises the documented deterministic contract.
Example 3
bulletRequirements = [1,1,1]
availableBullets = 2
poisonDoses = 3
return = 2
Case 3 exercises the documented deterministic contract.

Constraints
1 <= bulletRequirements.length <= 200000.
0 <= bulletRequirements[i], availableBullets <= 10^9.
0 <= poisonDoses <= bulletRequirements.length.

Reported by candidates. Source: FastPrep

Pattern and pitfall

What it really reduces to: each defeat costs one poison dose, so you can defeat at most poisonDoses monsters. Within that cap, you want as many as possible under the bullet budget. Sort bulletRequirements ascending, then walk through taking the cheapest monster while the running total stays within availableBullets and the count stays below poisonDoses. Stop at the first failure, since every later monster costs at least as much. The common pitfall is treating it as a knapsack and reaching for dynamic programming. With n up to 200000 that's far too slow and unnecessary. Another trap is overflow when summing values up to 10^9, so use a 64-bit sum in typed languages. Zero-cost monsters are fine, they still use a dose. Complexity is O(n log n) for the sort. If you freeze live, StealthCoder is the hedge that surfaces this greedy in seconds.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Maximize Monsters Defeated cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Salesforce's OA.

Salesforce reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximize Monsters Defeated FAQ

What's the trick in Maximize Monsters Defeated?+

Sort the bullet requirements ascending and take the cheapest monsters first. Poison doses cap the count, bullets cap the total cost. Greedy works because swapping any chosen monster for a pricier one never helps the count.

Is this a knapsack problem?+

No. Every item has the same value of one defeat, and the poison dose is just a count limit. When all values are equal, picking the cheapest items is optimal, so sorting beats DP and fits the 200000 length constraint.

How hard is this Salesforce OA question really?+

Easy. It's a sort and a loop. The difficulty is recognizing the theme hides a simple greedy and not overthinking it. Watch edge cases like zero doses, zero bullets, and sums that could overflow a 32-bit integer.

What's the time complexity I should state?+

O(n log n) from sorting, O(1) extra space beyond the sort if you sort in place. The scan after sorting is O(n). With n up to 200000, that runs comfortably.

How do I prepare for this in 48 hours?+

Practice a few sort-then-greedy problems where you take the smallest items under a budget. Write the loop by hand: sort, accumulate, break when the budget or count cap is hit. Test with the three given examples and a zero-dose case.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Salesforce.

OA at Salesforce?
Invisible during screen share
Get it