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
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
greedy
arrays
stock trading
proof of optimality
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported