FastPrepSorted Two Sum: All Index Pairs
Problems/Sorted Two Sum: All Index Pairs

Sorted Two Sum: All Index Pairs

The Walt Disney Company logoThe Walt Disney Company● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report explicitly describes a Two Sum II variant returning multiple results as indices, with no repeated results. It does not define duplicate-value position semantics, indexing base, output order or bounds. This practice uses sorted nondecreasing input, all one-based index pairs, lexicographic order and a 60-element bound. It preserves index multiplicity rather than collapsing equal-value pairs. About 85% of the reported task scope is represented, as an editorial estimate rather than recovered original detail.

Given a sorted integer array and a target, return every pair of different indices whose values sum to the target.

For this exercise, indices are one-based. Return pairs [i,j] with i < j, ordered by increasing i and then increasing j. Include every valid index pair exactly once. Equal values at different positions are different elements and may create multiple pairs; do not collapse them into one value pair. Return an empty array when there is no pair.

The one-based convention, duplicate-position semantics, ordering and bounds are explicit practice choices for the report’s multiple-result Two Sum II variant.

Function

allTwoSumPairs(numbers: int[], target: int) → int[][]

Examples

Example 1

numbers = [1,1,2,2]target = 3return = [[1,3],[1,4],[2,3],[2,4]]

Either position holding 1 can pair with either position holding 2, yielding [1,3], [1,4], [2,3] and [2,4]. Each is a different index pair.

Example 2

numbers = [-2,0,0,2]target = 0return = [[1,4],[2,3]]

The matching one-based pairs are [1,4] and [2,3]. The two zeros occupy different positions.

Constraints

  • 0 <= numbers.length <= 60
  • -1000000 <= numbers[i] <= 1000000
  • -2000000 <= target <= 2000000
  • numbers is sorted in nondecreasing order.

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Resizable Array-Backed Integer SetPHONE SCREEN · Seen Sep 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company hiring insights
Saved
class Solution {
    public int[][] allTwoSumPairs(int[] numbers, int target) {
        // Write your code here
    }
}
Checking account…