K Smallest Pair Sums
Updated
Problem statement
Given two integer arrays arr1 and arr2, both sorted in nondecreasing order, consider every index pair (i, j) and its sum arr1[i] + arr2[j].
Return the k smallest pair sums in nondecreasing order. Different index pairs are distinct, so equal values may appear more than once.
Function
kSmallestPairSums(arr1: int[], arr2: int[], k: int) → int[]Examples
Example 1
arr1 = [1,7,11]arr2 = [2,4,6]k = 4return = [3,5,7,9]The first four sums come from (1,2), (1,4), (1,6), and (7,2).
Example 2
arr1 = [1,1,2]arr2 = [1,2]k = 5return = [2,2,3,3,3]Different index pairs preserve duplicate sums.
Constraints
1 <= arr1.length, arr2.length <= 100000.- Both arrays are sorted in nondecreasing order.
- Every value is in
[-10^9, 10^9]. 1 <= k <= arr1.length * arr2.length.- Every returned sum fits in a signed 32-bit integer.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE 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
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Select the Top User MatchesDuolingo · PHONE SCREENDuolingo interview questions
- Meeting Rooms IIQuince · PHONE SCREENQuince interview questions
- Kth Largest Element in an ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
- Meeting Rooms IISecuronix · PHONE SCREEN
- Merge Multiple Sorted StreamsNVIDIA · PHONE SCREENNVIDIA interview questions