FastPrepAll Unique Two-Sum Pairs
Problems/All Unique Two-Sum Pairs

All Unique Two-Sum Pairs

Microsoft logoMicrosoft● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report from a Microsoft Data Scientist PhD internship asks for every unique pair in a Two Sum variant. We chose to output pairs of values, how to handle repeats, a fixed output order, the function signature and the limits.

Given an integer array nums and an integer target, return every distinct pair of values whose sum equals target.

Write each pair as [a,b] with a <= b. A pair [x,x] is valid only when x occurs at least twice. Return the pairs in increasing lexicographic order with no duplicates.

Function

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

Examples

Example 1

nums = [1,2,3,2,4,0]target = 4return = [[0,4],[1,3],[2,2]]

The three distinct value pairs sum to 4. Two copies of 2 make [2,2] valid.

Example 2

nums = [1,1,1]target = 2return = [[1,1]]

Repeated index choices do not create additional value-pair results.

Constraints

  • 0 <= nums.length <= 100000
  • -10^9 <= nums[i], target <= 10^9

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Valid Triangle NumberBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Count Winning Dice Face PairsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • 4SumAmazon · ONSITE INTERVIEW
  • Sort ColorsCapital One · ONSITE INTERVIEWCapital One interview questions
  • 3SumOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
  • Next and Previous Lexicographic PermutationAdobe · ONSITE INTERVIEWAdobe interview questions

Interview reports that mention this question

  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[][] allUniquePairs(int[] nums, int target) {
      // Write your code here.
    }

}
Checking account…