n items in a row. The item at position i costs prices[i] and brings a profit of profits[i].
Pick exactly three items at positions i < j < k whose prices strictly increase from left to right: prices[i] < prices[j] < prices[k]. The profit of such a trio is the sum of the three profits.
Return the largest profit a trio can bring, or -1 if no valid trio exists.prices=[5, 1, 4, 2, 6], profits=[3, 9, 1, 4, 2] → 15
The best pick is the items priced 1, 2 and 6 (positions 1, 3 and 4): prices rise from left to right and the profit is 9 + 4 + 2 = 15.
prices=[7, 7, 7], profits=[1, 2, 3] → -1
All prices are equal and the rise must be strict, so no valid trio exists and the answer is -1.
prices=[2, 9, 3, 8], profits=[10, 1, 1, 1] → 12
Nothing after the price 9 costs more, so the only trio is prices 2, 3, 8 with profit 10 + 1 + 1 = 12.
prices.length = profits.length ≤ 2000prices[i] ≤ 10⁶profits[i] ≤ 10⁶prices=[5, 1, 4, 2, 6], profits=[3, 9, 1, 4, 2]
15
Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.