You are given a geometric progression (GP) in which exactly one term is missing and represented by a placeholder (_). Your task is to find and return the missing term.
A geometric progression is a sequence in which the ratio between consecutive terms remains constant. The given sequence is guaranteed to form a valid GP when the missing term is restored.
Input: seq = [2, 4, _, 16]
Output: 8
Explanation: The common ratio is 2. Therefore, the missing term is 8.
Input: seq = [3, _, 27, 81]
Output: 9
Explanation: The common ratio is 3. Therefore, the missing term is 9.
Input: seq = [_, 10, 100, 1000]
Output: 1
Explanation: The common ratio is 10. Therefore, the first term is 1.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
2 4 _ 16 32
8
1 _ 9 27
3