Reported March 2025
Amazondynamic programming

Trader Joe Trades

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

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

Amazon's March 2025 OA is asking about stock trading optimization, and it's a classic dynamic programming trap. You've got a sequence of prices and you need to figure out the maximum profit with some constraint (usually buy-sell limits, cooldown, or transaction fees). The surface looks like a greedy problem. It's not. StealthCoder will catch the pattern in real time if you freeze on the state transitions, so you can move on without derailing your mental stack.

Pattern and pitfall

This problem lives in the DP space because you can't just pick the biggest dip-to-peak pair. Past decisions constrain future moves. You need to track state: are you holding stock, are you in cooldown, how many transactions have you used. Build a table where each row is a day and each column is a state (hold, sell, cooldown, or transaction count). Fill it bottom-up or use memoization. The trick is recognizing that the recurrence relation splits on whether you buy, sell, or wait today. Most candidates waste time on greedy approaches or miss the state definition entirely. The edge cases are empty arrays, single elements, and when buying is never profitable.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Trader Joe Trades 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 StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as best time to buy and sell stock. If you have time before the OA, drill that.

⏵ The honest play

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.

Trader Joe Trades FAQ

Is this the classic stock problem or a variant?+

Amazon rotates between the standard buy-sell-once, buy-sell-unlimited, cooldown, and k-transaction versions. Without the exact constraint, assume unlimited transactions unless you see language about fees or cooldown. The pattern is always DP either way.

How do I spot this is DP and not greedy?+

Greedy fails when past choices block future profit. If selling on day 3 locks you out of day 4 (cooldown), or you're limited to k buys, you need DP to explore the choice tree. Test greedy on the examples in your head first.

What's the state transition I need to remember?+

For each day, you have three choices: buy (if cash), sell (if holding), or wait. Your DP value depends on the max profit from each choice. Write the recurrence before code. It usually looks like dp[i][state] = max(do_nothing, do_action).

Can I solve this in one pass or do I need a 2D table?+

You can optimize space to O(1) or O(states) if you only keep the previous day's values, but the 2D table is clearer and safer under time pressure. Amazon won't dock you for space if logic is right.

What if the constraint is weird or not spelled out?+

Ask for clarification in the assessment chat if available. If not, code the unlimited buy-sell case as a baseline, then add cooldown or fee logic if hints emerge. Your interviewer will respect the fallback approach.

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

OA at Amazon?
Invisible during screen share
Get it