algoblazerEarly Access
LearnProblemsLeaderboard
Log inSign up

All problems

‹ Back to map
1 shown · 0/261 solved

Missing Arithmetic Term

BronzeCommunity Beta
Asked atLokal
Solve problem →
2000ms256MBAdded Aug 3, 2026Math & Number Theory

You are given an array arr: the remaining terms, in their original order, of an integer arithmetic progression (a sequence with a constant difference between consecutive terms) after exactly one interior term was removed (never the first or last term).

Return the removed term.

The common difference may be negative or zero; when it is zero, every term is equal and the removed term equals them.

Examples

Example 1

Input: arr = [3,7,11,19]
Output: 15
Explanation: The original progression was 3, 7, 11, 15, 19 with difference 4.

Example 2

Input: arr = [10,7,1]
Output: 4
Explanation: The original progression was 10, 7, 4, 1 with difference -3.

Example 3

Input: arr = [5,5,5]
Output: 5
Explanation: A constant progression, so the removed term equals every other term.

Constraints

  • 3≤3 \leq3≤ arr.length ≤105\leq 10^5≤105
  • −109≤-10^9 \leq−109≤ arr[i] ≤109\leq 10^9≤109
  • arr was produced by deleting exactly one interior term from a valid integer arithmetic progression.

Details

Solved by6 people
Time limit2000ms
Memory256MB
AddedAug 3, 20265 weeks ago
Math & Number Theory

More like this