Get Maximum Sum
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's "Get Maximum Sum" landed in August 2024 assessments, and it's testing whether you can spot the optimization pattern fast. You've got an array and you need to extract the maximum sum under some constraint, but the problem statement you're seeing might be vague on first read. This is classic Amazon: the trick is recognizing which dynamic programming or greedy substructure applies, then coding it cleanly under time pressure. StealthCoder is your safety net if you blank on the recurrence or the greedy choice.
Pattern and pitfall
Without the exact problem text, this likely falls into one of two buckets: either you're choosing non-adjacent elements for max sum (DP with state tracking), or you're finding the max subarray/subsequence under a specific constraint like "can skip at most K elements" or "sum must be contiguous." The common pitfall is jumping to brute force and getting TLE, or missing that a greedy approach (sort and pick) won't work because order or adjacency matters. Amazon loves testing whether you know when to use DP vs greedy. Build your state carefully: define what dp[i] means (max sum ending at i, or max sum using first i elements), then verify the transition. StealthCoder can remind you of the recurrence if you get stuck mid-code.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Get Maximum Sum 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as house robber. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Get Maximum Sum FAQ
Is this a DP problem or can I solve it greedy?+
If you can pick elements freely (no adjacency rule), it's greedy: sort and pick largest. If adjacency or gaps matter (non-adjacent elements, or you can only skip K items), it's DP. Read the constraint carefully. Amazon loves DP versions because greedy fails silently.
What should my DP state be?+
Common: dp[i] = max sum using elements up to index i. Or dp[i][0/1] = max sum at i, with or without taking element i. Define it clearly before you code. Wrong state = wrong answer even if logic seems right.
How do I avoid TLE on this?+
Don't brute force all subsets. Use DP (O(n) or O(n log n) with preprocessing). If the array is huge or the constraint is unusual, check if a sliding window or prefix sum optimization helps. Amazon usually accepts single-pass DP.
What's the most common mistake candidates make?+
Misreading the constraint. Is it non-adjacent, or contiguous, or "at most K operations?" Also: forgetting to handle negative numbers. If all nums are negative, the answer might be the least negative, or zero if you can skip all.
Can I solve this in 48 hours from scratch?+
Yes. Study the classic non-adjacent sum (house robber), then the max subarray (Kadane's). These two patterns cover most Amazon variants. Implement both, trace through a small example by hand, then practice under timer.