Maximize Profit Trading a Limited Merch Item With a One-Day Cooldown

Last updated: November 29, 2026

Quick Overview

Given daily resale prices of a limited-edition item on Douyin's e-commerce marketplace, return the maximum profit from any number of buy and sell trades, holding at most one unit and waiting a day after each sale before buying again.

ByteDance
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given daily resale prices of a limited-edition item on Douyin's e-commerce marketplace, return the maximum profit from any number of buy and sell trades, holding at most one unit and waiting a day after each sale before buying again.

Douyin e-commerce gives ByteDance a natural setting for state-machine DP, and this is a common screening problem for backend roles. The interviewer checks whether you can define the states (holding, just sold, resting) and their transitions without confusion.

What the Interviewer Expects
  • Identify three states: holding, just sold, and free to buy
  • Write transitions where buying is only allowed from resting
  • Initialize hold to negative infinity
  • Update all states from the previous day's values simultaneously
  • State O(n) time and O(1) space
Key Topics to Cover
state machine DP
1D dynamic programming
stock trading
space optimization
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Add a transaction fee per sale.
  • Limit the total number of trades to k.
  • Cooldown lasts c days instead of one: generalize the states.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list of daily prices. You may hold zero or one unit. After selling on day i you cannot buy on day i + 1. Output: maximum profit, 0 if no profitable trade exists or the list is empty....

High-Level Design

Model each day's end as one of three states. hold: you own a unit. sold: you sold today, so tomorrow is a cooldown. rest: you own nothing and may buy tomorrow. Transitions: hold = max(hold, rest - p),...


Submit Your Answer
Markdown supported