BudiBadu Logo

Cascade Step Chimes

Array Easy 0 views
Like3

The technical objective is to determine the total number of bronze chimes produces across a series of stepped overlooks. The chime sequence begins with a single base chime. For each subsequent step, a new guiding chime is added, and the entire soundscape from the previous step is tripled through fanned-out stone echoes.

Specifically, the total count of chimes $f(n)$ follows the recurrence $f(n) = 2 imes 3^n - 1$ where $n$ represents the number of additional terraces after the base landing. The solution must calculate this precise total efficiently for any non-negative integer of steps, ensuring that musicians at Silvervein Falls can maintain the traditional harvest festival structure. The output must be an integer representing the combined soundscape of all risers and echo reflections.

Examples

Example 1
Input
steps = 4
Output
161
Explanation

Four additional steps mean another guiding chime plus a tripled echo of everything below, totaling 161 chimes.

Example 2
Input
steps = 0
Output
1
Explanation

Only the base chime plays, so the crowd hears a single note.

Example 3
Input
steps = 2
Output
17
Explanation

The second step adds one guiding chime and repeats the prior soundscape three times, ending with seventeen chimes.

Algorithm Flow

Recommendation Algorithm Flow for Cascade Step Chimes - Budibadu
Recommendation Algorithm Flow for Cascade Step Chimes - Budibadu

Best Answers

java
class Solution {
    public int count_chimes(int steps) {
        return 2 * (int) Math.pow(3, steps) - 1;
    }
}