MEDIUMasked at 4 companies

Maximum Profit From Trading Stocks

A medium-tier problem at 47% community acceptance, tagged with Array, Dynamic Programming. Reported in interviews at BlackRock and 3 others.

Founder's read

You're staring at a stock price array on your screen during the assessment. Buy low, sell high sounds simple until you realize the constraints: maybe you can only do one transaction, maybe unlimited, maybe you need cooldown between trades. BlackRock, Snowflake, Walmart Labs, and Oracle ask this problem at medium difficulty with a 46% acceptance rate, which means half the people bombing it got the state machine wrong. If you blank on whether to use DP or greedy, StealthCoder surfaces the right approach in seconds, invisible to the proctor.

Companies asking
4
Difficulty
MEDIUM
Acceptance
47%

Companies that ask "Maximum Profit From Trading Stocks"

If this hits your live OA

Maximum Profit From Trading Stocks 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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The trick is recognizing that different variants demand different state machines. One transaction is a simple two-pass greedy. Multiple transactions without constraints is greedy again, you just sum every upswing. Add cooldown or a transaction limit, and you're tracking states: holding vs. not holding, or counting transactions. The pattern candidates miss: they code greedy when they need DP, or they over-engineer DP when greedy works. The problem lives in Array and Dynamic Programming for a reason. You'll see the prices, count them, and have maybe 30 minutes to nail the state logic. If the variant hits and you haven't drilled the exact constraint set, StealthCoder is the hedge. The proctor sees your submission; they don't see the invisible overlay that showed you the DP table structure.

Pattern tags

The honest play

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

Maximum Profit From Trading Stocks 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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Profit From Trading Stocks interview FAQ

Is this really asked at BlackRock and Oracle, or is that self-reported noise?+

It's in the official company tag data for all four: BlackRock, Snowflake, Walmart Labs, Oracle. That's solid signal. Medium difficulty and 46% pass rate means it's a real filter, not a warm-up.

What's the actual trick everyone misses?+

They assume one variant and code it. The variant matters: one transaction is O(n) greedy, unlimited is also greedy, but add a cooldown or limit and you need DP state tracking. Read the constraint twice before you code.

Is this a DP problem or greedy?+

Both. Unlimited transactions without cooldown is greedy (sum all gains). One transaction is greedy (track min, max profit). Cooldown or transaction limits force DP. Input will tell you which. Array and Dynamic Programming are both listed because the problem family spans both.

How much time should I spend on this in an OA?+

For the basic variant, 12 to 15 minutes if you know the pattern. For constrained variants with DP, 20 to 30. At 46% acceptance, most people overshoot time or get the state machine wrong. If you're stuck after 10 minutes, you don't own the pattern yet.

Can I just memorize all the variants and pick one?+

No. The variant is always explicit in the problem. Read the constraints: one transaction, unlimited, cooldown period, max transactions limit. Once you spot the constraint, the approach is deterministic. That's your signal to recognize whether greedy or DP wins.

Want the actual problem statement? View "Maximum Profit From Trading Stocks" 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.