FastPrepTop K Pair Sums From One Array
Problems/Top K Pair Sums From One Array

Top K Pair Sums From One Array

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives all two-number combinations from one integer array, keeps repeats, and has a follow-up for the top K largest pair sums using sorting and a max heap that avoids duplicate states. We chose that pairs use different indices, the output order, 64-bit sums, the examples, and the input limits. Our version is about 89% the same as the reported question.

Given an integer array nums, every pair of distinct indices i < j produces the sum nums[i] + nums[j].

Return the k largest pair sums, from largest to smallest. Count each different index pair separately, even when values or sums are equal.

Function

topKPairSums(nums: int[], k: int) → long[]

Examples

Example 1

nums = [1,2,3]k = 2return = [5,4]

The pair sums are 5 from 2+3, 4 from 1+3, and 3 from 1+2.

Example 2

nums = [4,4,1]k = 3return = [8,5,5]

The two different index pairs containing 1 both contribute a sum of 5.

Example 3

nums = [-5,-1,2,3]k = 4return = [5,2,1,-2]

The four largest sums are 2+3, -1+3, -1+2, and -5+3.

Constraints

  • 2 <= nums.length <= 100000.
  • -1000000000 <= nums[i] <= 1000000000.
  • 1 <= k <= min(100000, nums.length * (nums.length - 1) / 2).

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
  • Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Top K Largest Values from a StreamThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
  • Minimum Meeting Rooms Without a Sweep LineGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Top K Frequent ElementsCapgemini · ONSITE INTERVIEWCapgemini interview questions
  • Kth Largest Element in an ArrayOneTrust · ONSITE INTERVIEW

Interview reports that mention this question

  • Google New Grad Four-Round Coding Onsite: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long[] topKPairSums(int[] nums, int k) {
        // write your code here
    }
}
Checking account…