Back to problems

Compute Stock Profit with One or Unlimited Transactions

Algorithm · Meta · Medium

Given an array prices representing the price of a stock on consecutive days, return a two-element result. The first value, oneTransactionProfit, is the largest profit achievable by making at most one purchase and one later sale. The second value, unlimitedTransactionsProfit, is the largest total profit achievable by making any number of non-overlapping purchase/sale pairs. You may hold no more than one share at any moment. Every sale must occur on a day after its…

Checking your access…