Maximum Profit with Unlimited Stock Transactions
Company: Point72
Role: Quantitative Researcher
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Given daily stock prices, compute the maximum profit from any number of buy-and-sell transactions. Work through the function contract, boundary cases, correctness argument, and time and space complexity expected in a production-quality solution.
Read the full Point72 Quantitative Researcher interview experience this question came from
Constraints
- 0 <= len(prices) <= 200000.
- 0 <= prices[i] <= 10^9 for every day.
- At most one share may be held, every sale follows a buy, and there are no fees or cooldowns; the result fits signed 64-bit range.
Examples
Input: ([],)
Expected Output: 0
Explanation: No trading day permits no transaction.
Input: ([5],)
Expected Output: 0
Explanation: A single price cannot form a profitable transaction.
Hints
- Compare empty, single-day, flat, strictly rising, and strictly falling price histories.
- Include several separated rises with declines between them and verify that every transaction remains legal.
- Use repeated full-range rises to exercise a result larger than a single price value.