MEDIUMasked at 4 companies

Best Time to Buy and Sell Stock with Cooldown

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

Founder's read

You're allowed to buy and sell a stock multiple times, but there's a catch: after you sell, you can't buy again the next day. That cooldown rule breaks the naive greedy approach, which is why this problem has shown up at Google, Visa, Geico, and TikTok. The acceptance rate sits at 60 percent, which means most people either solve it cleanly or get trapped in state-management hell. If you blank on the state transitions during your live OA, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
4
Difficulty
MEDIUM
Acceptance
60%

Companies that ask "Best Time to Buy and Sell Stock with Cooldown"

If this hits your live OA

Best Time to Buy and Sell Stock with Cooldown 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 by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.

Get StealthCoder
What this means

The trick is recognizing this as a state machine, not a greedy problem. At each day, you're in one of three states: holding stock, not holding stock but in cooldown, or ready to buy again. A simple dynamic programming table tracks the maximum profit for each state at each day. Most candidates try to optimize greedily (buy before every spike, sell at every peak) and miss that cooldown breaks that pattern. The state transitions are the core insight: if you sell today, you're forced into cooldown tomorrow. If you're in cooldown, you move to 'ready to buy' the next day. Build a DP table and iterate forward, and the answer falls out. This is where Array and Dynamic Programming meet in a way that feels deceptively simple once you name the states. StealthCoder is your hedge if the state transitions don't click under pressure.

Pattern tags

The honest play

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

Best Time to Buy and Sell Stock with Cooldown 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. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Best Time to Buy and Sell Stock with Cooldown interview FAQ

Is this still asked at FAANG companies?+

Yes. Google, TikTok, and Visa all report it in their hiring data. It's a medium-difficulty problem that filters candidates who can model state machines, so it stays in rotation at top-tier companies.

What's the difference between this and the regular buy/sell stock problem?+

Without cooldown, you can buy and sell on consecutive days and just take every profitable micro-spike. Cooldown forces you to choose: do I sell today and sit out tomorrow, or hold longer. That constraint makes it a state problem instead of a greedy one.

What's the main trap candidates fall into?+

Trying to simulate transactions day by day without naming states explicitly. You end up tracking too many variables or making contradictory transitions. Once you define held, cooldown, and ready states, the DP recurrence becomes mechanical.

Does this require a 2D DP table?+

Not strictly. Most people build a 2D table (days x states) for clarity, but you can optimize to O(1) space by tracking only the three state values from the previous day. The logic is the same either way.

How does this connect to the Array and Dynamic Programming topics?+

You iterate through the price array (Array) and use DP to track the maximum profit at each state transition. It's a clean example of DP applied to a sequential decision problem where past choices constrain future options.

Want the actual problem statement? View "Best Time to Buy and Sell Stock with Cooldown" 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.