BudiBadu Logo
00:00

Canyon Echo Verse

Recursion Easy 0 views

At the Crescent Canyon amphitheater, storytellers welcome dusk by chanting a verse that rolls along the stone walls. The performance starts with a single voiced line from the narrator at the canyon floor. Before the chant continues, a caller announces how many echo layers the chorus will invite that evening. Each layer adds one guiding verse to begin the stanza, and the canyon sends back every line from the previous layer twice, bouncing from cliff to cliff in perfect cadence.

The routine never changes even when visitors from distant villages arrive. After the guiding verse is spoken, the rock faces release the lines from the prior layer on both sides, giving the impression of voices answering from hidden alcoves. Elders insist that repeating the earlier chorus twice keeps the history clear and the rhythm easy to follow under the stars.

Your job is to figure out how many verses the audience hears once all layers finish echoing. The input is a non-negative integer layers, representing how many echo layers join after the initial verse. When layers equals zero, the narrator's line stands alone. For every higher layer, add one new verse for the guide and include two copies of the entire chorus from the previous layer. Return an integer with the total verses heard at the end.

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.

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.

BudiBadu Logo

Canyon Echo Verse

Recursion Easy 0 views

At the Crescent Canyon amphitheater, storytellers welcome dusk by chanting a verse that rolls along the stone walls. The performance starts with a single voiced line from the narrator at the canyon floor. Before the chant continues, a caller announces how many echo layers the chorus will invite that evening. Each layer adds one guiding verse to begin the stanza, and the canyon sends back every line from the previous layer twice, bouncing from cliff to cliff in perfect cadence.

The routine never changes even when visitors from distant villages arrive. After the guiding verse is spoken, the rock faces release the lines from the prior layer on both sides, giving the impression of voices answering from hidden alcoves. Elders insist that repeating the earlier chorus twice keeps the history clear and the rhythm easy to follow under the stars.

Your job is to figure out how many verses the audience hears once all layers finish echoing. The input is a non-negative integer layers, representing how many echo layers join after the initial verse. When layers equals zero, the narrator's line stands alone. For every higher layer, add one new verse for the guide and include two copies of the entire chorus from the previous layer. Return an integer with the total verses heard at the end.

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.

00:00
Loading editor...
Test Results

Run your code to see test results

Click the Submit button to execute your solution

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.