PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Google

Find k pairs with smallest sums

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving with ordered data structures, specifically understanding how to combine two sorted arrays efficiently, priority-queue or merge-based reasoning, and time/space complexity analysis in the coding and algorithms domain.

  • easy
  • Google
  • Coding & Algorithms
  • Software Engineer

Find k pairs with smallest sums

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given two **sorted** integer arrays `arr1` and `arr2` (each sorted in non-decreasing order), and an integer `k`. Consider all possible pairs formed by taking one element from `arr1` and one element from `arr2`. For indices `i` and `j`, the pair is `(arr1[i], arr2[j])` with sum `arr1[i] + arr2[j]`. Your task is to return the **k pairs** `(arr1[i], arr2[j])` with the smallest sums. If there are fewer than `k` total possible pairs, return all possible pairs. You may return the pairs in any order. --- ### Function Signature (one possible form) ```text kSmallestPairs(arr1: List[int], arr2: List[int], k: int) -> List[Tuple[int, int]] ``` --- ### Example ```text arr1 = [1, 7, 11] arr2 = [2, 4, 6] k = 3 ``` All possible pairs and their sums are: - (1, 2) -> 3 - (1, 4) -> 5 - (1, 6) -> 7 - (7, 2) -> 9 - (7, 4) -> 11 - (7, 6) -> 13 - (11, 2) -> 13 - (11, 4) -> 15 - (11, 6) -> 17 The 3 pairs with the smallest sums are: ```text [(1, 2), (1, 4), (1, 6)] ``` (The order among these returned pairs does not matter.) Explain an efficient algorithm to solve this problem and analyze its time and space complexity. You may assume the arrays are large, so a solution that explicitly generates and sorts all `len(arr1) * len(arr2)` pairs is too slow.

Quick Answer: This question evaluates algorithmic problem-solving with ordered data structures, specifically understanding how to combine two sorted arrays efficiently, priority-queue or merge-based reasoning, and time/space complexity analysis in the coding and algorithms domain.

Related Interview Questions

  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Solve Shortest Paths and Rental Allocation - Google (medium)
  • Solve Two Array Optimization Problems - Google (medium)
Google logo
Google
Nov 1, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
4
0

You are given two sorted integer arrays arr1 and arr2 (each sorted in non-decreasing order), and an integer k.

Consider all possible pairs formed by taking one element from arr1 and one element from arr2. For indices i and j, the pair is (arr1[i], arr2[j]) with sum arr1[i] + arr2[j].

Your task is to return the k pairs (arr1[i], arr2[j]) with the smallest sums. If there are fewer than k total possible pairs, return all possible pairs.

You may return the pairs in any order.

Function Signature (one possible form)

kSmallestPairs(arr1: List[int], arr2: List[int], k: int) -> List[Tuple[int, int]]

Example

arr1 = [1, 7, 11]
arr2 = [2, 4, 6]
k = 3

All possible pairs and their sums are:

  • (1, 2) -> 3
  • (1, 4) -> 5
  • (1, 6) -> 7
  • (7, 2) -> 9
  • (7, 4) -> 11
  • (7, 6) -> 13
  • (11, 2) -> 13
  • (11, 4) -> 15
  • (11, 6) -> 17

The 3 pairs with the smallest sums are:

[(1, 2), (1, 4), (1, 6)]

(The order among these returned pairs does not matter.)

Explain an efficient algorithm to solve this problem and analyze its time and space complexity. You may assume the arrays are large, so a solution that explicitly generates and sorts all len(arr1) * len(arr2) pairs is too slow.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.