← 返回 jpmorgan 的题目列表All Index Pairs Whose Values Sum to K
类型:online_judge
Problem: All Index Pairs Whose Values Sum to K
Given an unsorted integer array nums and an integer K, return every index pair (i, j) satisfying:
0 <= i < j < len(nums)
nums[i] + nums[j] == K
The array may contain duplicate values. Every pair of distinct indices must be included, even when the values are identical.
For example, for nums = [1, 1, 1] and K = 2, the result contains three pairs: (0, 1), (0, 2), and (1, 2).
Input Format
Line 1: integer n, the array length.
Line 2: n space-separated integers representing nums.
Line 3: integer K.
Output Format
Print one index pair per line as i j.
Print pairs in the order in which they are discovered while scanning the array. Print nothing if no valid pair exists.
Constraints
0 <= n <= 2 * 10^5
-10^9 <= nums[i], K <= 10^9
The number of output pairs may be O(n^2).
Example
Input
4
2 7 11 15
9
Output
0 1