878751. Geometric Progression Term

Easy

Geometric Progression Term

Summary

Find the term at a given position in a geometric progression. The geometric progression is defined by an initial value and a common ratio.

Detailed Explanation

To solve this problem, we can use the formula for a geometric progression: term = a * r^(n-1), where a is the initial value, r is the common ratio, and n is the position of the term. We need to calculate the term at a given position n.

Here's the step-by-step breakdown:

  1. Calculate the term at position n: term = a * r^(n-1)
  2. Return the calculated term

Time complexity: O(1) since we're performing constant-time operations Space complexity: O(1) since we're not using any extra space that scales with the input size

Optimized Solutions

Java

View on GeeksforGeeks
public class GeometricProgression {
    public static double getTerm(double a, double r, int n) {
        return a * Math.pow(r, n - 1);
    }
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.