FastPrepFind the Pair With a Target Sum
Problems/Find the Pair With a Target Sum

Find the Pair With a Target Sum

Adobe logoAdobe● EasyFULLTIMEINTERNPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem finds the two values, at different positions of an integer array, that add up to a target, and returns them smallest first. An Adobe Computer Scientist 1 report names the classic pair-sum question (two values in a list that reach a given total) as the first coding task of its first round, and leaves the choice of the best method to the candidate. It gives no output format, edge rules, limits or examples.

Our choices: exactly one matching pair, the two values returned smallest first, a position never used twice, at most 10^4 values from -10^9 to 10^9, and new examples.

The judged task matches the report at about 90%.

Given an integer array nums and an integer target, find the two numbers at two different positions that add up to target. Exactly one such pair of positions exists.

Return the two numbers as [a, b] with a <= b. A position cannot be used twice, but the same value may appear at two positions.

Function

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

Examples

Example 1

nums = [8,-3,14,6,11]target = 19return = [8,11]

8 + 11 = 19, and no other two positions add up to 19. The smaller value comes first: [8, 11].

Example 2

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

The two 7s are at different positions, so they form the pair: [7, 7].

Example 3

nums = [5,1,9]target = 10return = [1,9]

5 + 5 would need two 5s, but there is only one, and a position cannot be used twice. The pair is 1 + 9.

Constraints

  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • -2 * 10^9 <= target <= 2 * 10^9
  • exactly one pair of positions i < j has nums[i] + nums[j] == target

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[] findPairWithSum(int[] nums, int target) {
    // Write your code here.
}
Checking account…