Algorithm · IBM · Medium
An analyst reviews a stock across n days. On day i, the stock price is price[i], and the profit associated with that day is profit[i]. Choose three days (i, j, k) satisfying both i < j < k and price[i] < price[j] < price[k]. Among all valid choices, maximize the sum profit[i] + profit[j] + profit[k]. Return the greatest possible total profit, or -1 when no such triplet exists. Function Description Implement getMaximumProfit with these parameters: int price[n]: the stock…
Checking your access…