BudiBadu Logo

Canyon Echo Verse

Array Easy 0 views
Like2

The technical objective is to determine the total number of lines echoing in a stone amphitheater after a specific sequence of layered vocal performances. The chant begins with an initial narrator line, and each subsequent layer adds a new guiding verse, while the canyon walls replicate the entire previous chorus twice—once from each side.

Specifically, the total count of verses $f(n)$ follows the squared geometric progression $f(n) = (2^{n+1}-1)^2$ (where $n$ is the number of echo layers). This pattern emerges because the ritual doubles both the length and the width of the performance's vocal presence, creating a perfectly balanced rhythmic structure. The solution must provide a precise integer count for any non-negative integer of layers, enabling storytellers to maintain the exact cadence required for Crescent Canyon traditions.

Examples

Example 1
Input
layers = 0
Output
1
Explanation

Only the narrator speaks, so one verse is heard.

Example 2
Input
layers = 2
Output
9
Explanation

The second layer adds a verse and repeats the earlier chorus twice.

Example 3
Input
layers = 4
Output
49
Explanation

Four layers continue the same pattern, leading to forty-nine verses echoing through the canyon.

Algorithm Flow

Recommendation Algorithm Flow for Canyon Echo Verse - Budibadu
Recommendation Algorithm Flow for Canyon Echo Verse - Budibadu

Best Answers

java
class Solution {
    public int count_echo_verses(int layers) {
        int base = (1 << (layers + 1)) - 1;
        return base * base;
    }
}