A financial strategist at Amazon Web Services (AWS) is analyzing a collection of profitable investments, each represented by an integer array. Every value in the array indicates the annual gain of a particular investment. The strategist's goal is to identify all unique investment pairs whose combined annual returns exactly match a given target value.
Unique pairs are defined as combinations that vary by at least one element (i.e., their values are not at the exact same positions or do not have identical values in identical positions).
Given the array of gains, compute the number of unique investment pairs whose sum equals the specified target return.
Complete the function getDistinctPairs in the editor.
getDistinctPairs has the following parameter(s):
- 1.
int investmentReturns[n]: an array of integers representing each investment’s yearly gain - 2.
goal: an integer denoting the targeted combined return
Returns
int: the total number of unique pairs that meet the target return
stocksProfit = [5, 7, 9, 13, 11, 6, 6, 3, 3] target = 12 return = 3
1 ≤ n ≤ 5 x 10^50 ≤ investmentReturns[i] ≤ 10^90 ≤ goal ≤ 5 x 10^9- Maximum Product New RatingOA · Seen Jul 2026
- Permutation SorterOA · Seen Jul 2026
- Maximum Final ValueSeen Jul 2026
- Minimum Delivery Center InconvenienceOA · Seen Jun 2026
- Unfulfilled Customers by Inventory PriorityOA · Seen Jun 2026
- Minimum Operations to Make the Integer ZeroSeen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
public int getDistinctPairs(int[] investmentReturns, int goal) {
// write your code here
}