FastPrepEvery Index Pair That Sums to a Target
Problems/Every Index Pair That Sums to a Target

Every Index Pair That Sums to a Target

Adobe logoAdobe● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem lists every pair of positions in an array whose values add up to a target, with repeated values allowed and every matching pair reported. An Adobe Computer Scientist II (frontend) report names, for its first round, a variation of the classic pair-sum question that wants every index with repeats allowed, and adds nothing else about it.

Our choices: pairs as [i, j] with i < j sorted by i then j, a position never paired with itself, at most 2000 values up to 10^9 in size, at most 1500 pairs in the answer, and new examples.

The judged task matches the report at about 80%.

Given an integer array nums (values may repeat) and an integer target, find every pair of positions i < j with nums[i] + nums[j] == target.

Return the pairs as [i, j], sorted by i and then by j. Pairs with the same values at different positions are all listed. A position cannot be paired with itself. Return an empty list if there are none.

Function

allPairIndexes(nums: int[], target: int) → int[][]

Examples

Example 1

nums = [3,5,3,1,5]target = 8return = [[0,1],[0,4],[1,2],[2,4]]

Each of the two 3s (indexes 0 and 2) pairs with each of the two 5s (indexes 1 and 4), giving four pairs. Written smaller index first and sorted: [0, 1], [0, 4], [1, 2], [2, 4]. The 1 would need a 7.

Example 2

nums = [4,4,4]target = 8return = [[0,1],[0,2],[1,2]]

Any two of the three 4s add up to 8: [0, 1], [0, 2], [1, 2]. One position cannot be used twice.

Example 3

nums = [2,7,-1]target = 4return = []

No two values add up to 4 (2 + 7 = 9, 2 + (-1) = 1, 7 + (-1) = 6), so the answer is empty.

Constraints

  • 2 <= nums.length <= 2000
  • -10^9 <= nums[i] <= 10^9
  • -2 * 10^9 <= target <= 2 * 10^9
  • the answer has at most 1500 pairs

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int[][] allPairIndexes(int[] nums, int target) {
    // Write your code here.
}
Checking account…