597. Maximum Profitable Triplets With Increasing Prices I
Given that the prices and profits of length n in the 0-indexed arrays. An item at a store has a price of prices[i] and a profit of profits[i], and there are n goods in total.
Three objects must be chosen under the following circumstances:
- costs[i] < costs[j] < costs[k] where i < j < k.
The profit would be profits[i] + profits[j] + profits[k] if we chose products whose indices i, j, and k met the criteria mentioned above.
Return the highest potential profit and -1 if selecting three things under the specified conditions is not feasible.
Example 1:
Input : prices = [5, 4, 3, 2, 1], profits = [100, 20, 21, 60, 10]
Output : -1
Explanation :
We can't select any triplet of indices such that the condition holds, so we return -1.
Example 2:
Input : prices = [10, 5, 2, 15, 9, 25], profits = [100, 20, 21, 60, 10, 75]
Output : 235
Explanation :
We can select the indices i = 0, j = 3, k = 5.
So total profit is = profits[i] + profits[j] + profits[k] => 100 + 60 + 75 -> 235.
Now Your Turn!
Pick the correct output for the given inputInput : prices = [6, 9, 1, 5, 2, 7], profits = [100, 20, 21, 60, 10, 5]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 3 <= prices.length == profits.length <= 2000
- 1 <= prices[i] <= 106
- 1 <= profits[i] <= 106