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.

Example 1:

Input: layers = 0
Output: 1

Example 2:

Input: layers = 2
Output: 49

Example 3:

Input: layers = 4
Output: 961

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;
    }
}