Maximum Profit from an Increasing Price Triplet
Updated
Problem statement
An analyst observes a stock over n days. The stock price on day i is price[i], and the profit associated with that day is profit[i].
Choose three indices i < j < k such that price[i] < price[j] < price[k]. Return the maximum possible value of profit[i] + profit[j] + profit[k]. If no valid triplet exists, return -1.
Function
getMaximumProfit(price: int[], profit: int[]) → intExamples
Example 1
price = [1, 5, 3, 4, 6]profit = [2, 3, 4, 5, 6]return = 15The optimal triplet is (3, 4, 5) in one-based indexing. Its prices satisfy 3 < 4 < 6, and its total profit is 4 + 5 + 6 = 15.
Example 2
price = [3, 2, 1]profit = [10, 20, 30]return = -1No three indices have strictly increasing prices.
More Odoo interview questions
Similar questions at other companies
- Rolling MetricsAkuna Capital · OAAkuna Capital interview questions
- Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
- Minimum Bridge TurnbacksBNSF Railway · OABNSF Railway interview questions
- Minimum Cost to Attend Required CoursesVisa · OAVisa interview questions
- Fill a Time Window with SongsMicrosoft · OAMicrosoft interview questions
- Maximum Taxi EarningsWells Fargo · OAWells Fargo interview questions
- Longest Increasing Subsequence from Two ArraysSquarepoint Capital · OASquarepoint Capital interview questions
- Split Array Largest SumLinkedIn · OALinkedIn interview questions
- Longest Increasing SubsequenceAtlassian · OAAtlassian interview questions
- Longest Increasing Subsequence LengthApple · OAApple interview questions