← Citadel Interview Insights

Citadel·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Citadel SWE interview that went deep on stock trading DP problems. Two parts, both leetcode-style but with real follow-up pressure on justifying your state choices and squeezing out space complexity. Not a vibe-check round at all.

Questions Asked (2)

Q1

You can buy and sell a stock any number of times but hold at most one share at a time. Write a DP solution to maximize profit, explain why you chose those states, and then optimize it down to O(1) space.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The base solution came out fine but then they asked me to justify why I picked the states I did and I kind of fumbled it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining DP states that capture the maximum profit at each day given whether you hold a stock. Derive the recurrence relations, then show how to reduce space by observing that only the previous day's states are needed. Finally, optimize to O(1) space by maintaining only two variables for the current states.

Pro tip: Emphasize the invariant that at most one share is held, and connect the DP to the greedy insight that you can sum all positive daily price differences. This shows you understand the problem deeply and can optimize beyond the obvious DP.

1. Define DP States

Define dp[i][0] as max profit up to day i with no stock held, and dp[i][1] as max profit up to day i holding one stock. Explain that these states capture all possible actions while respecting the one-share constraint.

2. Write Recurrence Relations

For dp[i][0]: max of dp[i-1][0] (do nothing) and dp[i-1][1] + prices[i] (sell). For dp[i][1]: max of dp[i-1][1] (do nothing) and dp[i-1][0] - prices[i] (buy). Initialize dp[0][0]=0, dp[0][1]=-prices[0].

3. Optimize Space to O(1)

Observe that dp[i] depends only on dp[i-1]. Replace the 2D array with two variables: cash (max profit with no stock) and hold (max profit with stock). Update them iteratively for each price.

4. Explain and Validate

Walk through a small example to verify correctness. Discuss time complexity O(n) and space O(1). Mention that the solution effectively sums all positive price differences, which is the greedy insight.

Key Points to Mention

  • State definition: dp[i][0] and dp[i][1] represent max profit with and without stock.
  • Recurrence: dp[i][0] = max(dp[i-1][0], dp[i-1][1] + price[i]); dp[i][1] = max(dp[i-1][1], dp[i-1][0] - price[i]).
  • Space optimization: only previous day's states are needed, so use two variables.
  • Time complexity: O(n) where n is number of days.
  • Greedy equivalence: maximum profit equals sum of all positive price increases.
  • Edge cases: empty array, single day, decreasing prices.

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

Q2

Generalize the stock trading problem to allow at most k transactions. Define a 3-dimensional DP table over day, transaction count, and whether you're currently holding a share, then derive the transition equations.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where it got rough.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Define a 3D DP table where dp[i][j][0/1] represents the maximum profit up to day i with at most j transactions, and 0/1 indicates whether you hold a share. Derive transitions by considering the choice to buy, sell, or do nothing, and optimize space to O(k) if needed.

Pro tip: Emphasize that the state definition naturally handles the 'at most k' constraint by allowing fewer transactions, and mention that the DP can be optimized to O(k) space since only the previous day's states are needed.

1. Define the DP state

Let dp[i][j][0] be the max profit up to day i with at most j transactions and no stock held; dp[i][j][1] with a stock held. Base cases: dp[0][j][0] = 0, dp[0][j][1] = -prices[0] for j>=1.

2. Derive transition equations

For each day i and transaction count j (1..k): dp[i][j][0] = max(dp[i-1][j][0], dp[i-1][j-1][1] + prices[i]); dp[i][j][1] = max(dp[i-1][j][1], dp[i-1][j][0] - prices[i]).

3. Handle base cases and edge cases

Initialize dp for day 0: dp[0][j][0] = 0, dp[0][j][1] = -prices[0] for j>=1. If k >= n/2, the problem reduces to unlimited transactions, which can be solved greedily.

4. Optimize space and time

Since dp[i] depends only on dp[i-1], reduce space to O(k) by iterating j in reverse or using two arrays. Time complexity is O(n*k).

5. Return the final answer

The maximum profit is dp[n-1][k][0] (or max over j of dp[n-1][j][0] if 'at most k' is interpreted as up to k).

Key Points to Mention

  • State definition: dp[i][j][0/1] with clear meaning of each dimension.
  • Transition equations: buy, sell, or hold decisions.
  • Base cases and initialization for day 0 and j=0.
  • Space optimization from O(n*k) to O(k) using rolling arrays.
  • Time complexity O(n*k) and how it compares to the unlimited transaction case.
  • Handling of 'at most k' by allowing fewer transactions (e.g., dp[i][j][0] = max(dp[i][j-1][0], ...)).

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