Maximum Profitable Triplets With Increasing Prices II
A hard-tier problem at 43% community acceptance, tagged with Array, Binary Indexed Tree, Segment Tree. Reported in interviews at IBM and 0 others.
Maximum Profitable Triplets With Increasing Prices II is a hard problem that appears in IBM's hiring loop and sits at a 43% acceptance rate, meaning most candidates don't solve it cold in an assessment. You need to find three indices where prices strictly increase and the profit formula (price[j] - price[i]) * price[k] is maximized. The catch: a naive O(n^3) scan won't pass. This problem filters out candidates who can't recognize when a segment tree or binary indexed tree becomes necessary.
Companies that ask "Maximum Profitable Triplets With Increasing Prices II"
Maximum Profitable Triplets With Increasing Prices II is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe problem requires optimizing across all valid triplet combinations, which sounds like dynamic programming but is actually a range-query problem in disguise. For each potential middle element, you need the minimum price to its left and the maximum profit contribution to its right, both under strict ordering constraints. A brute force pass fails on time. You need either a Binary Indexed Tree or Segment Tree to track running minimums and maximums as you scan left-to-right, reducing the problem from cubic to O(n log n). Most candidates freeze when they realize the greedy approach breaks. If you hit this in a live OA and the solution doesn't click, StealthCoder solves it invisible to the proctor, surfacing the tree-based approach in seconds.
Pattern tags
You know the problem.
Make sure you actually pass it.
Maximum Profitable Triplets With Increasing Prices II recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Profitable Triplets With Increasing Prices II interview FAQ
Is this really asked at IBM and other major companies?+
Yes. It's in IBM's hiring reports. At 43% acceptance, it's a genuine hard problem, not a warm-up. Companies use it to filter for candidates who know advanced data structures, not just basic DP.
What's the trick that most people miss?+
Thinking it's solvable with nested loops or simple memoization. The insight is that you need to query range minimums and maximums across changing constraints. That's when you reach for a Binary Indexed Tree or Segment Tree.
Do I really need a Segment Tree or can Binary Indexed Tree work?+
Binary Indexed Tree is sufficient and often cleaner. Segment Tree gives more flexibility but adds complexity. Both achieve O(n log n). Choose BIT unless the problem forces you to handle point updates on a pre-built structure.
How does this relate to the first version of the problem?+
Without seeing the first version, the 'II' suggests added constraints or a larger input size that breaks the simpler approach. Expect either stricter ordering rules or n values that force a log-n per element solution.
What preparation actually works for this?+
Know how to build and query a BIT for range minimums and maximums. Practice the scan-and-query pattern on simpler problems first. Then solve this under timed conditions to lock the pattern into muscle memory before the live OA.
Want the actual problem statement? View "Maximum Profitable Triplets With Increasing Prices II" on LeetCode →