Maximum Profit From Repeated Azure Spot Price Swings
Last updated: November 29, 2026
Quick Overview
Given the daily price of an Azure spot capacity reservation that you can buy and resell, with at most one unit held at a time and unlimited transactions, return the maximum total profit.
Microsoft
November 29, 20260
0
0 solved
Given the daily price of an Azure spot capacity reservation that you can buy and resell, with at most one unit held at a time and unlimited transactions, return the maximum total profit.
This is a warm-up style question in Microsoft phone screens, dressed up as trading reserved Azure capacity. Interviewers use it to check that you can justify a greedy argument rather than just recall a pattern.
What the Interviewer Expects
- State the constraint clearly: hold at most one unit, sell before buying again
- Argue that summing all positive day over day gains is optimal
- Write an O(n) one-pass solution
- Handle empty and monotonically decreasing input
- Explain the argument with a small price chart
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if each transaction has a fixed fee?
- What if you are limited to at most two transactions?
- What if there is a one day cooldown after selling?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of prices, one per day.
- You may buy and sell as often as you like but can hold at most one unit.
- Buying and selling on the same day is allowed and nets zero.
- Output: maximum total ...
High-Level Design
Any multi-day holding period from day a to day b earns p[b] - p[a], which telescopes into the sum of daily differences p[i] - p[i-1] for i in (a, b]. Some of those daily differences may be negativ...