Reported August 2024
Akunagreedy

Maximum Amount of Profit

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

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

Akuna's August OA included a profit maximization problem, and you're likely staring at it wondering if there's a trick. The problem almost always boils down to finding the best buy-sell pair or sequence of trades on a price series. Your instinct to spot the pattern matters more than coding speed here. StealthCoder is your safety net if you blank on the recurrence or indexing, but the real win is recognizing the structure in the first 30 seconds.

Pattern and pitfall

Profit problems usually fall into one of two buckets: single transaction (find max difference where buy comes before sell) or multiple transactions (sum all upswings). If the problem allows unlimited trades, the greedy trick is to buy before every rise and sell before every fall. If it's one trade only, you track the minimum price seen so far and calculate profit at each step. The pitfall is off-by-one errors on indices or missing that you need to iterate left-to-right maintaining state. StealthCoder reads the exact constraints and feeds you the pattern instantly, so you never waste time on the wrong approach during your live attempt.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Maximum Amount of Profit 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. If you're reading this with an OA window open, you're who this was built for.

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 Akuna's OA.

Akuna reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Amount of Profit FAQ

Is this a single trade or multiple trades problem?+

Read the problem text carefully. Single trade: find max(price[j] - price[i]) where i < j. Multiple trades: sum every (price[i+1] - price[i]) where price[i+1] > price[i]. Akuna typically specifies, so don't assume.

What's the one-liner trick for unlimited trades?+

If allowed to buy and sell as much as you want, just sum all positive differences: sum(max(0, prices[i] - prices[i-1])). It's greedy and it works because you capture every upswing.

How do I avoid the index-out-of-bounds trap?+

Always check array length before indexing. For single trade, track min price as you iterate forward, compute profit at each step. Never assume the list has at least 2 elements without testing first.

Is there a DP angle here, or is it just greedy?+

Single trade is O(n) one-pass, no DP needed. Multiple trades is greedy in O(n). If the problem adds constraints like 'at most k transactions', then DP becomes necessary. Read the constraint carefully.

Can I solve this in less than 5 minutes?+

Yes. Single trade is 20 lines max. Multiple trades is even shorter. The time sink is usually clarifying the constraint, not the code. Lock down the problem statement first.

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

OA at Akuna?
Invisible during screen share
Get it