Get Maximum Amount
Reported by candidates from IBM's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
IBM asked this in August 2024, and it's a straightforward optimization problem that catches candidates off guard because the naive approach works but the optimal one saves you. You're trying to maximize some amount given constraints, which usually means greedy or dynamic programming. The trick is spotting whether you can solve it left-to-right with a single pass or if you need to track state. StealthCoder will catch you if you freeze on the recurrence relation.
Pattern and pitfall
Without the full problem text, the pattern is almost certainly greedy or dynamic programming. If it's 'get the maximum amount', you're either picking items with the best ratio (greedy), or you're building up a table of best amounts at each step (DP). The common trap: candidates write a greedy solution that works on examples but fails on adversarial inputs where you need to reconsider earlier choices. The DP approach requires you to define state correctly, usually 'maximum amount achievable with i items considered' or 'maximum amount achievable up to position j'. StealthCoder becomes your safety net if you code greedy, test it mentally, and suddenly realize it's broken at interview time.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Get Maximum Amount 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass IBM's OA.
IBM reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Get Maximum Amount FAQ
Is this a knapsack-style problem?+
Likely. If you're maximizing an amount subject to a constraint (like weight, items, or steps), think 0-1 or unbounded knapsack. Set up a DP table where each cell represents the best amount achievable under that constraint. If amounts can be fractional, greedy by ratio is faster.
Will greedy work here?+
Greedy is tempting but risky. It works if the problem has optimal substructure and a clear 'best choice at each step' (like coin change with the right denominations). Test your greedy solution against edge cases: what if the best item is expensive but breaks your constraint? That's where DP wins.
How do I set up the DP state?+
Define dp[i] as the maximum amount achievable with i units of the constraint, or dp[i][j] if you're tracking two dimensions. Fill bottom-up, always asking 'what's the best decision at this step that leads to the max overall'. Transition is usually 'take it or leave it'.
What's the trick IBM is looking for?+
Clean state definition and recognizing whether the constraint is single or multi-dimensional. IBM interviewers care more about your reasoning than speed. Explain your DP recurrence out loud before coding. A wrong greedy followed by a pivot to DP looks worse than a clean DP from the start.
Can I code this in under 15 minutes?+
DP version yes, if you're clear on the state. Worst case you write the nested loops, fill the table, and return the answer. Don't overthink optimizations. A working O(n^2) or O(n*m) solution beats a broken O(n) greedy attempt every time.