Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find the Missing Term in an Arithmetic Progression

Basic Acceptance 82.87% Points 10

You are given an arithmetic progression (AP) in which exactly one term is missing and represented by a placeholder (_). Your task is to find and return the missing term.

An arithmetic progression is a sequence in which the difference between consecutive terms remains constant. The given sequence is guaranteed to form a valid AP when the missing term is restored.

Examples
Example 1

Input: seq = [2, 4, _, 8, 10]

Output: 6

Explanation: The common difference is 2. Therefore, the missing term is 6.

Example 2

Input: seq = [5, 10, 15, _, 25]

Output: 20

Explanation: The common difference is 5. Therefore, the missing term is 20.

Example 3

Input: seq = [_, 3, 5, 7]

Output: 1

Explanation: The common difference is 2. The term immediately before 3 is 1.

Constraints
  • 3 <= number of known terms <= 105
  • The sequence is a valid AP apart from the one missing term.
Topics
Introduction Data Structures Basics Array
Companies
Samsung Cisco
Added 01 Nov 2026 82.87% acceptance
Ln 1, Col 1Sign in to save your code
1 3 _ 7 9
5