← 返回 amazon 的题目列表Find All Distinct Pairs of Stocks
类型:online_judge
Given an array of stock price differences and a target profit, the task is to find all distinct pairs of stocks whose profits sum up to the target. The stock pairs (i, j) and (j, i) should be considered the same. Return all pairs that meet the condition.
Input:
stocks: List[int]. An array representing stock price differences.
target_profit: int. Target profit value.
Output:
List[Tuple[int, int]]. Return all distinct stock pairs with the target profit.
Example:
stocks = [1, 3, 2, 4, 2, 3]
target_profit = 5
output = [(1, 4), (2, 3)]
Constraints:
Assume no negative stock price differences.
Optimize for space and time complexity as much as possible.
Example
Input
6
1 3 2 4 2 3
5