Maximize profit with transaction fee
CoinbaseSoftware Engineer · OnsiteLast updated
This interview question evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer for Maximize profit with transaction fee states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Given an array of daily stock prices and a fixed transaction fee charged on each sell, compute the maximum profit achievable with any number of buy–sell transactions. Provide an O(n) time, O(
- or O(n) space algorithm, prove correctness, and describe how you would handle edge cases such as empty input or strictly decreasing prices.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.