FastPrepStock Trading with a Fee and a Cooldown
Problems/Stock Trading with a Fee and a Cooldown

Stock Trading with a Fee and a Cooldown

Citadel logoCitadel● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Seen in one Citadel Securities account from Singapore, posted in May 2026, from an experienced engineer interviewing for a trading-infrastructure software job. The loop was booked as four one-hour video calls, one after another on the same day. In the second one, the candidate got a single dynamic programming question about buying and selling a stock, close to a well-known practice problem, and then several follow-ups that changed the rules: a charge on each trade, a waiting period after selling, and the two together. The account does not give the exact wording or the exact rules.

We chose unlimited trades as the starting point, a fixed fee per completed trade, a single waiting day after each sale, and one function with the fee and the waiting day as inputs, so each follow-up is one part of the same problem. The limits and all examples are ours.

Our version is about 60% the same as the reported question.

You are given prices, where prices[i] is the price of one share of a stock on day i. A trade means buying one share on one day and selling it on a later day. You may make as many trades as you like, but you can hold at most one share at a time, so you must sell before you buy again.

Two extra rules can apply:

  • Fee: every completed trade costs fee, paid once per buy-and-sell pair.
  • Cooldown: when cooldown = 1, you cannot buy on the day right after a sale. When cooldown = 0, there is no waiting day.

Return the largest total profit you can make. Making no trades gives 0.

The problem comes in four parts, and one function answers all of them:

  1. Part 1: no fee and no cooldown (fee = 0, cooldown = 0).
  2. Part 2: a fee on every trade (cooldown = 0).
  3. Part 3: a cooldown day after every sale (fee = 0, cooldown = 1).
  4. Part 4: both rules at once.

Function

maxProfit(prices: int[], fee: int, cooldown: int) → int

Examples

Example 1

prices = [3,6,1,5,2,8]fee = 0cooldown = 0return = 13

Part 1. Take every rise: buy at 3 and sell at 6, buy at 1 and sell at 5, buy at 2 and sell at 8. The profit is 3 + 4 + 6 = 13.

Example 2

prices = [3,6,1,5,2,8]fee = 2cooldown = 0return = 7

Part 2. The same three trades still pay after a fee of 2 each: 1 + 2 + 4 = 7. Merging trades loses money here: buying at 1 and selling at 8 gives only 5, plus 1 from the first trade, which makes 6.

Example 3

prices = [3,6,1,5,2,8]fee = 0cooldown = 1return = 9

Part 3. Buy at 3 and sell at 6. The next day, with price 1, is the cooldown. Skip the 5, buy at 2 and sell at 8. The profit is 3 + 6 = 9. Buying at 1 and selling at 8 would give only 7.

Example 4

prices = [3,6,1,5,2,8]fee = 2cooldown = 1return = 5

Part 4. Two plans tie at 5. One is to buy at 3, sell at 6, then buy at 2 and sell at 8, for (3 - 2) + (6 - 2) = 5. The other is to buy at 1 and sell at 8, for 7 - 2 = 5.

Constraints

  • 1 <= prices.length <= 5 * 104
  • 1 <= prices[i] <= 5 * 104
  • 0 <= fee <= 5 * 104
  • cooldown is 0 or 1

More Citadel Onsite Interview questions

  • Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Removal PoolONSITE INTERVIEW · Seen Sep 2026
  • Centered K-by-K Submatrix SumsONSITE INTERVIEW · Seen Aug 2026
  • Search Suggestions with a Prefix TreeONSITE INTERVIEW · Seen Aug 2026
  • Traverse Interior Matrix Cells in Row-Major OrderONSITE INTERVIEW · Seen Aug 2026
  • Limit Order Book Matching EnginePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Fixed-Capacity Circular BufferONSITE INTERVIEW · Seen Jun 2026
  • Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
  • 2048 Simulation and Board CodecONSITE INTERVIEW · Seen Jan 2026

Similar questions at other companies

  • Assign Escalations to TeamsAmazon · ONSITE INTERVIEW
  • Distinct Subset SumsGoogle · ONSITE INTERVIEW
  • Count Subsets With a Target SumSafe Security · ONSITE INTERVIEW
  • Maximum Subarray Sum with One DeletionOracle · ONSITE INTERVIEW
  • Best Time to Buy and Sell Stock IIKotak Mahindra Bank · ONSITE INTERVIEW
  • Coin ChangeMicrosoft · ONSITE INTERVIEW
  • Maximum SubarrayUpstart · ONSITE INTERVIEW
  • Smallest Sufficient TeamExpedia · ONSITE INTERVIEW
  • Maximum Product SubarrayHartford Financial Services · ONSITE INTERVIEW
  • Word BreakMoveworks · ONSITE INTERVIEW

Citadel interview experiences

  • Citadel Securities Quant Researcher Intern Loop: 1 Experience
  • Citadel Securities Research Engineer Interview: 1 Experience
  • Citadel Securities SWE Intern First Round: 2 Experiences
  • Citadel Securities Experienced SWE Interviews: 1 Experience
  • Citadel SWE Intern Later Rounds and Superday: 13 Experiences
  • Citadel SWE Intern First-Round Questions: 20 Experiences
See Citadel hiring insights
Saved
class Solution {
    public int maxProfit(int[] prices, int fee, int cooldown) {
      // Write your code here.
    }
}
Checking account…