Requirements
Three levels, usually in order. The interviewer escalates only after the previous level is clean.
- Level 1 — Single transaction. Given
prices[]whereprices[i]is the stock price on dayi, return the maximum profit from at most one buy / sell pair (buy must precede sell, hold time unbounded). - Level 2 — Unlimited transactions, no concurrent holdings. Same input. You may transact arbitrarily many times but may hold at most one share at any moment. Return the maximum total profit.
- Level 3 — At most k transactions. Given
prices[]and integerk, return the maximum profit from at mostkcomplete buy / sell pairs.
Examples
Examples below are taken verbatim from candidate-reported sessions.
- Level 1 — interviewer asked for the one-pass solution and explicitly probed why tracking
min_so_farwas sufficient instead of a full two-pointer sweep. - Level 2 — interviewer pushed for an
O(1)space optimization after the initial DP solution. - Level 3 — interviewer accepted the
dp[i][j][0/1]formulation and probed whether thej-dimension could be compressed, the time / space complexity at largek, and what happens whenk >= n / 2(degenerates to Level 2).
One Citsec onsite reportedly bolted on transaction fees and a one-day cooldown as follow-ups beyond Level 3, asking for the corresponding state-machine updates.
Notes
- Level 1 is the canonical one-pass minimum-tracking pattern. Time
O(n), spaceO(1). - Level 2 has two equivalent framings: greedy summation of positive deltas, or two-state DP (
hold/not-hold) compressible to two scalars. Most interviewers prefer the DP framing because it generalizes to Level 3 without rewriting. - Level 3 uses
dp[j][0/1]wherejis transactions used; space isO(k)after compressing the day axis with rolling updates. Watch the buy-side update ordering —not-holdmust update beforeholdwhen iterating in-place to avoid double-counting. - The fee / cooldown variants add one term or one extra state to the transition; clean state-machine bookkeeping is the discriminator.
- Common failure mode: when extending to Level 3, candidates re-derive the DP from scratch rather than naming the state explicitly. Verbalize the state (
dp[day][txn_count][holding]) before writing.
Preparation
- Drill the full LC 121 / 122 / 123 / 188 / 309 / 714 ladder in one sitting; the Citsec ask reproduces 3-5 rungs in 30 minutes.
- Practice giving the generalization talk track in under 90 seconds: state, transition, base case, complexity, space optimization. Interviewers grade this explicitly.
- Rehearse the
k >= n/2collapse argument out loud — it is a frequent follow-up. - For Citsec specifically, prepare to switch language mid-round if the interviewer flips from Python to C++ after seeing your resume.

