Best Time to Buy and Sell Stock
A easy-tier problem at 55% community acceptance, tagged with Array, Dynamic Programming. Reported in interviews at Bank of America and 119 others.
Best Time to Buy and Sell Stock shows up everywhere. Bank of America, Morgan Stanley, Citigroup, HSBC, and 116 other companies ask it. The problem looks trivial on the surface, which is exactly why candidates blank on it live. You're given an array of prices and need to find max profit from a single buy-sell transaction. Half the people who see it online don't solve it efficiently. If this problem hits your live assessment and you freeze on the trick, StealthCoder surfaces a working solution in seconds, invisible to the proctor.
Companies that ask "Best Time to Buy and Sell Stock"
Best Time to Buy and Sell Stock 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. Made for the engineer who has done the work but might still blank with a webcam pointed at him.
Get StealthCoderThe trap is iterating through prices twice or using nested loops. The actual pattern is a single pass where you track the minimum price seen so far and calculate profit at every step. Keep a running minimum, update max profit as you scan right. No extra space, O(n) time, done. Most candidates overthink it or try a brute force approach that times out on large inputs. The problem sits at the intersection of Array and Dynamic Programming because the decision at each price depends only on what came before. When you hit this live and aren't sure about the one-pass algorithm, StealthCoder eliminates the gap between knowing the concept and submitting clean code.
Pattern tags
You know the problem.
Make sure you actually pass it.
Best Time to Buy and Sell Stock recycles across companies for a reason. It's easy-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. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Best Time to Buy and Sell Stock interview FAQ
Is this problem actually easy or do people get it wrong in interviews?+
It's categorized as easy but the acceptance rate is 55 percent, meaning a lot of people either don't solve it or submit suboptimal code. The trap is overthinking it or using nested loops instead of tracking min price in one pass.
Do big tech companies really ask this or is it just banks?+
All tiers ask it. You see it at Bank of America, Morgan Stanley, and Citigroup, but also at Blizzard, Bolt, Garmin, and 114 other companies across finance, gaming, and tech. It's a universal screening problem.
What's the pattern I should memorize for the live OA?+
One pass through the array. Track min_price and max_profit. At each step, update max_profit as the max of current profit (current_price minus min_price) and previous max_profit. Update min_price if you see a lower one.
How does this relate to Dynamic Programming if it's just one pass?+
It's DP because the profit at each position depends on the optimal decision before it (lowest price seen). You're building up the solution incrementally rather than recomputing. Same principle as DP, just not in matrix form.
Does this problem come up after other array problems or early in the loop?+
It often appears early because it's a screening filter. Over 120 companies report it, so treat it as a must-solve before your OA. If you haven't locked the one-pass pattern, you're at risk of losing time.
Want the actual problem statement? View "Best Time to Buy and Sell Stock" on LeetCode →