Problem · Array
Profitable Project Pairs
Learn this problemProblem statement
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[]) → longExamples
Example 1
profit = [2, 3, 7, 1, 1]implementationCost = [3, 4, 5, 1, 2]return = 4The 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^5profit.length = implementationCost.length = n1 <= profit[i], implementationCost[i] <= 10^9
More Akuna Capital problems
- Binary CircuitOA · Seen Jul 2026
- Items SortOA · Seen Jul 2026
- Minimize Malware Spread by Removing a NodeOA · Seen Jul 2026
- Maximum K-Star SumOA · Seen Jul 2026
- Array Challenge (QR Intern)OA · Seen Jul 2026
- Communications HandlerOA · Seen Jul 2026
- K Smallest SubstringOA · Seen Jul 2026
- Delivery Management SystemOA · Seen Jul 2026