โ† Deloitte questions

Find Pairs whose sum equal to a target sum

Filed under Deloitte

Free read 2 of 3

Determine if index pairs or value pairs are required, and if duplicate pairs should be filtered out.

The question

Given an array of integers and a target sum, find all unique pairs of elements in the array that add up to the target sum.

Constraints

  • Array length between 1 and 10^5.
  • Elements can be negative, zero, or positive.

Examples

Input
arr = [2, 4, 3, 5, 7, 8, -1], target = 7
Output
[[2, 5], [4, 3], [8, -1]]
Why
These pairs sum up to the target 7.

Approach

  1. Determine if index pairs or value pairs are required, and if duplicate pairs should be filtered out.

Tips

  • What they are testing: Test with duplicate values in the array and targets with no matching pairs.
  • Common mistake: Returning duplicate pairs when the same combination appears multiple times in the array.

Related Deloitte questions

Collected from public candidate posts and coding forums. Updated Nov 2026.