MEDIUMasked at 1 company

Maximize Total Tastiness of Purchased Fruits

A medium-tier problem at 64% community acceptance, tagged with Array, Dynamic Programming. Reported in interviews at LinkedIn and 0 others.

Founder's read

You're buying fruit at a market. Each fruit has a price and a tastiness value, but here's the catch: the more you buy of the same fruit, the less tasty each additional one becomes. You've got a budget cap. The problem asks you to pick which fruits and how many of each to maximize total tastiness without blowing your budget. LinkedIn has asked this one. The trick isn't greedy. You can't just grab the tastiest fruit first because the diminishing returns on quantity flip the math. This is a DP problem hiding inside a shopping scenario.

Companies asking
1
Difficulty
MEDIUM
Acceptance
64%

Companies that ask "Maximize Total Tastiness of Purchased Fruits"

If this hits your live OA

Maximize Total Tastiness of Purchased Fruits is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.

Get StealthCoder
What this means

The obvious trap is sorting by tastiness per unit and filling your budget greedily. That fails because buying 10 units of one fruit drops its value per unit each time, and at some point a 'less tasty' fruit becomes smarter than a fifth copy of the expensive one. You need dynamic programming: state is your remaining budget, and you track the max tastiness achievable. For each fruit, you iterate through how many units you could buy (1, 2, 3, etc.) and update the DP table. The transition cost increases as you buy more of the same fruit. If you're live in an assessment and can't quickly remember the recurrence relation, StealthCoder identifies the pattern and surfaces a working DP solution in seconds, invisible to the proctor.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Maximize Total Tastiness of Purchased Fruits recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximize Total Tastiness of Purchased Fruits interview FAQ

Is this harder than standard knapsack?+

Yes. Classic 0/1 knapsack has fixed item cost. Here each unit of a fruit costs more as quantity grows, so the state space is trickier. You must iterate through quantities per fruit and update DP carefully. Expect 20-30 minutes if you've done knapsack; longer if not.

Will the budget always be small?+

Not stated in the problem spec, so assume it could be large. Your DP table size depends on budget, not item count. If budget is 10,000 and you have 3 fruits, you're building a 10,001-size array. Optimize space if needed.

How do I know when to stop buying more of one fruit?+

Your DP loop handles it. You iterate quantity from 1 to as many as your budget allows for that fruit. If buying a 4th unit costs more than your remaining budget or doesn't improve the answer, the DP transition naturally skips it.

Is there a greedy trick I'm missing?+

No. Greedy fails here because tastiness per unit is non-linear in quantity. You must explore the state space. DP is the right tool. Any greedy heuristic will miss the optimal mix on real test cases.

Why is acceptance rate 64% if it's medium difficulty?+

Most candidates either recognize it as knapsack and nail it, or they don't see the DP structure and waste time on greedy. Recognition of the pattern is the skill. Once you spot DP, the code follows. That split tracks the people who've seen similar problems.

Want the actual problem statement? View "Maximize Total Tastiness of Purchased Fruits" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.