Profitable Project Pairs
Reported by candidates from Akuna Capital's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Akuna Capital reported this one in July 2026, and the detail that matters is hiding in the constraints: n goes up to 2 * 10^5. That kills the obvious double loop over every (i, j) pair. The problem is Count Pairs With Positive Sum in disguise. Subtract cost from profit to get net values, then count pairs that add to more than zero. If you've got an OA invite and 48 hours, learn this shape cold. It's sort plus two pointers, and it shows up in many costumes. StealthCoder is the safety net if your mind goes blank on the live OA, but the idea fits in your head.
The problem
A team can choose any two distinct projects from n available projects. For project i: profit[i] is its expected profit. implementationCost[i] is its implementation cost. A pair of projects (i, j), where 0 <= i < j < n, is profitable when: (profit[i] - implementationCost[i]) + (profit[j] - implementationCost[j]) > 0 Return the number of profitable project pairs. Complete the function getProfitablePairs, which accepts the arrays profit and implementationCost and returns the required count. Function getProfitablePairs(profit: int[], implementationCost: int[]) → long Examples Example 1 profit = [2, 3, 7, 1, 1] implementationCost = [3, 4, 5, 1, 2] return = 4 The net profits are [-1, -1, 2, 0, -1]. The profitable pairs are: (0, 2): -1 + 2 = 1 (1, 2): -1 + 2 = 1 (2, 3): 2 + 0 = 2 (2, 4): 2 + (-1) = 1 No other pair has a positive combined net profit, so the result is 4. Constraints 1 <= n <= 2 * 10^5 profit.length = implementationCost.length = n 1 <= profit[i], implementationCost[i] <= 10^9
Reported by candidates. Source: FastPrep
Pattern and pitfall
Build net[i] = profit[i] - implementationCost[i]. Order doesn't matter for pairs, so sort net ascending. Put left at 0 and right at n-1. If net[left] + net[right] > 0, then every index from left to right-1 pairs with right, so add right - left to the count and move right down. Otherwise move left up. That's O(n log n) total. The pitfalls are all about size. Return a long, because the count can reach about 2 * 10^10. Net values can be as low as -10^9 and as high as 10^9, so a sum of two fits in 32 bits, but use long anyway. Also, don't count i == j, which the pointer loop avoids with left < right. If you freeze during the live OA, StealthCoder runs invisibly and can hand you the sorted two-pointer solution so you can check it against the example.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Profitable Project Pairs cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Akuna Capital's OA.
Akuna Capital reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Profitable Project Pairs FAQ
What's the trick in Profitable Project Pairs?+
Collapse each project into one number, profit minus cost. Then the question is how many pairs of those numbers sum to more than zero. Pair order doesn't matter, so you can sort the array and use two pointers instead of checking every pair.
Why does brute force fail here?+
With n up to 2 * 10^5, checking every pair means roughly 2 * 10^10 comparisons. That times out. Sorting and two pointers gets you to O(n log n), which is comfortable for this input size.
How does the two-pointer count work exactly?+
After sorting, if net[left] + net[right] > 0, every element between left and right also works with right, because they're at least as large as net[left]. Add right - left, then decrement right. If the sum is not positive, increment left.
What data type should the answer use?+
Use a 64-bit integer. The function signature returns long for a reason. In the worst case almost every pair is profitable, which is about 2 * 10^10 pairs, far beyond a 32-bit int. Compute the nets in long too, to be safe.
How do I prepare for this in 48 hours?+
Solve the same shape in a few forms: pairs with sum above a target, two-sum variants, and count pairs after sorting. Practice writing the two-pointer loop from memory and test it by hand on the example, where the nets are [-1, -1, 2, 0, -1] and the answer is 4.