← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026Remote

Summary

Meta SWE coding round, one question the whole time. It looked like a stock trading problem but the cooldown twist is what they actually care about. Took me a minute to realize brute force wasn't going to cut it.

Questions Asked (1)

Q1

Given an array of daily stock prices, find the maximum profit you can make from unlimited buy/sell transactions, with the constraint that after selling you must wait one day before buying again.

Algorithms & Data Structures
Author's notes

I knew the basic buy-low-sell-high problem cold, so I started heading down that path and had to stop myself.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose a dynamic programming solution that tracks two states: holding a stock and not holding a stock, with a cooldown period after selling. Optimize to O(n) time and O(1) space by maintaining variables for the maximum profit in each state.

Pro tip: Mention that the cooldown can be handled by using a 'cooldown' state or by adjusting the transition from selling to buying with a one-day delay, and emphasize that this approach generalizes to similar problems like 'Best Time to Buy and Sell Stock with Cooldown'.

1. Understand the problem

Restate the problem in your own words, confirm that you can make unlimited transactions, and that after selling you must wait one day before buying again. Ask clarifying questions about edge cases (e.g., empty array, single day).

2. Define states and transitions

Define two states: 'hold' (holding a stock) and 'sold' (not holding a stock, and not in cooldown). Also consider a 'cooldown' state. Derive the recurrence relations for each state.

3. Implement DP with O(1) space

Initialize variables for the maximum profit in each state at day 0. Iterate through the prices, updating the states based on the transitions. Return the maximum profit from the 'sold' or 'cooldown' state at the end.

4. Test with examples

Walk through a small example (e.g., [1,2,3,0,2]) to verify the DP transitions and ensure the cooldown is respected. Check edge cases like increasing prices, decreasing prices, and empty array.

5. Analyze complexity and discuss optimizations

State that the time complexity is O(n) and space complexity is O(1). Mention that the solution can be further simplified by using two variables instead of three, and discuss potential variations.

Key Points to Mention

  • Dynamic programming with states: hold, sold, and cooldown.
  • Recurrence relations: hold[i] = max(hold[i-1], sold[i-1] - price[i]); sold[i] = max(sold[i-1], hold[i-1] + price[i]); cooldown[i] = sold[i-1].
  • Space optimization: use variables instead of arrays to achieve O(1) space.
  • Time complexity: O(n) single pass.
  • Edge cases: empty array, single element, strictly increasing/decreasing prices.
  • Comparison with the unlimited transactions without cooldown problem and how the cooldown modifies the solution.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.