FastPrepAll Pairs with Target Sum
Problems/All Pairs with Target Sum

All Pairs with Target Sum

Deloitte logoDeloitte● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Deloitte new grad online assessment. The report asks for all pairs of elements that reach the target, and says one index cannot be used twice. It leaves out how duplicates are counted, the order of results, and limits that work in every language. We defined those. Our version is about 94% the same as the reported question.

You are given an integer array numbers and an integer target. Return one pair for every index pair (i, j) with i < j and numbers[i] + numbers[j] = target.

Represent each pair as [smallerValue, largerValue]. Different index pairs remain different results, so duplicate values may create repeated rows. Sort all returned rows lexicographically by their first value and then their second value.

Function

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

Examples

Example 1

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

The valid index pairs contribute value pairs [1,3] and [2,2].

Example 2

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

Each of the three positions containing 1 can pair with either of the two positions containing 2, producing six distinct index pairs.

Example 3

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

Both -2 + 4 and 0 + 2 equal the target. The rows are already in lexicographic order.

Constraints

  • 1 <= numbers.length <= 2000
  • -10^9 <= numbers[i], target <= 10^9
  • The number of returned rows fits in memory.

More Deloitte Online Assessment questions

  • Seventh Nearest PalindromeOA · Seen May 2026
  • Minimum Deletions for a Non-PalindromeOA · Seen Jul 2025
  • Minimum-Cost Solar Rooftop AllocationOA · Seen Jul 2025
  • Pair Elements with Even SumsOA · Seen Jul 2025
  • Count Divisible PermutationsOA · Seen Jan 2025
  • Largest Element in an ArrayOA · Seen Nov 2024
  • Install Carbon FiltersOA · Seen Oct 2023
  • Longest Substring with Even OccurrencesOA · Seen Oct 2023
  • Maximum Sum RectangleOA · Seen Apr 2022
  • Annual Bank Balance with Monthly Card FeesOA · Seen Jan 2022

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
  • Items SortAkuna Capital · OAAkuna Capital interview questions
  • Count Cross-Array Target-Sum PairsVisa · OAVisa interview questions
  • Array Rank TransformTata Consultancy Services · OATata Consultancy Services interview questions
  • Find Max Health SumAmazon · OA
  • Influencers SquadTikTok · OATikTok interview questions
  • Count Teams Outscoring a Target TeamBloomberg LP · OABloomberg LP interview questions
  • Count Soldiers with a Next-Rank SuperiorMarshall Wace · OAMarshall Wace interview questions

Interview reports that mention this question

  • Deloitte New Grad Tech OA and Interview Questions: 14 Experiences
All Deloitte interview questionsSee Deloitte hiring insights
Saved
class Solution {
    public int[][] allPairsWithTargetSum(int[] numbers, int target) {
        // Write your solution here.
    }
}
Checking account…