FastPrepTwo Sum: All Pairs
Problems/Two Sum: All Pairs

Two Sum: All Pairs

Zillow logoZillow● EasyFULLTIMEINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Asked at Zillow from 2014 to 2022. A Software Development Engineer candidate, who gave no level, was asked in a 2014 phone interview, after a take-home task, to find all pairs of values in an array that add up to a target. Two software engineering intern candidates name the task in 2022. One lists two sum among the topics of an internship process with a technical screen and a final round, without saying which round it came in. The other got a changed version of two sum in a live coding screen on a shared online editor and did not say what was changed.

We use the all-pairs version, because it is the only one a report describes. The reports do not give limits or say how the input is passed, how repeated values count, or how the answer is written. Here the function gets the array and the target as integers. Two values from different positions form a pair, so a value pairs with itself only when it appears at least twice. Each pair of values is returned once, as [smaller, larger], and the pairs are sorted by their smaller value; with no pair the answer is an empty array. The array holds 2 to 10^4 values, and values and the target are between -10^9 and 10^9, the limits of the well-known two sum task.

Our version is about 80% the same as the reported question.

You are given an integer array nums and an integer target. Find every pair of values in nums that adds up to target.

The two values of a pair must come from two different positions in the array, so a value can pair with itself only when it appears at least twice. Return each pair of values only once, even when several pairs of positions give it.

Write each pair as [a, b] with a <= b, and return the pairs sorted by a in increasing order. If no two values add up to target, return an empty array.

Function

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

Examples

Example 1

nums = [3,8,5,1,7,4]target = 9return = [[1,8],[4,5]]

Two pairs add up to 9: 1 + 8 and 4 + 5. Each pair is written smaller value first, and [1, 8] comes before [4, 5] because 1 < 4. The values 3 and 7 have no partner, because 6 and 2 are not in the array.

Example 2

nums = [2,6,2,6,4,4,4]target = 8return = [[2,6],[4,4]]

The positions of the two 2s and the two 6s give four pairs of positions that add up to 8, but they all give the same values, so [2, 6] is returned once. The value 4 appears three times, so it can pair with itself, and [4, 4] is also returned once.

Example 3

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

5 + 5 = 10, but 5 appears only once, and a position cannot be used twice. No other two values add up to 10, so the answer is an empty array.

Example 4

nums = [-4,0,10,-6,4]target = 4return = [[-6,10],[0,4]]

Negative values pair like any other: -6 + 10 = 4 and 0 + 4 = 4. The pair starting with -6 comes first. -4 would need 8, which is not in the array.

Constraints

  • 2 <= nums.length <= 104
  • -109 <= nums[i] <= 109
  • -109 <= target <= 109

More Zillow Phone Screen questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Time Based Key-Value StorePHONE SCREEN · Seen Feb 2024
  • Filter Formatted Records by CriteriaPHONE SCREEN · Seen Sep 2023
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Jump GamePHONE SCREEN · Seen Dec 2022
  • Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
  • Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
  • Employee Free TimePHONE SCREEN · Seen Oct 2022
  • First Unique Character in a StringPHONE SCREEN · Seen Oct 2022
  • K-th Smallest Number in a StreamPHONE SCREEN · Seen Oct 2022

Similar questions at other companies

  • Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
  • Price CheckBlue Origin · PHONE SCREEN
  • Majority ElementByteDance · PHONE SCREENByteDance interview questions
  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Find Unique ElementsCisco · PHONE SCREENCisco interview questions
  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Two SumAmazon · OA · PHONE SCREEN
  • Employee Count Median, Mean and ModeClay · PHONE SCREEN
  • Two SumBNSF Railway · PHONE SCREENBNSF Railway interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public int[][] findAllPairs(int[] nums, int target) {
        // Write your code here.
    }
}
Checking account…