BudiBadu Logo

Festival Drum Echoes

Stack Easy 4 views
Like19

The Riverlight Drum Festival arrives with nightfall, and the organizes control the intensity through Levels. Level zero is just the opening beat. For every level after, the lead drummer adds One new strike, and every beat heard in the previous level is echoed twice. In Festival Drum Echoes, your task is to report the total count of beats heard by the audience.

The "secret sauce" here is Recursive Echo Logic. For any level i, the total beats are: 1 + (2 * total_from_level_i-1). This doubling echo creates a performance that feels like thunder weaving through stone corridors! As the layers deepen, the sound experience stacks, turning a quiet plaza into a wall of rhythm. Return the final result as a single integer, as the ritual never produces fractional sounds. This calculation helps the festival planners design the yearly show and balance the lighting sequences with the intensity of the drums. Precision is key!

Keep the algorithm focused on one clear invariant and update path so correctness is easy to verify from left to right. This reduces accidental branching errors and helps ensure the final output stays consistent with the problem contract across random and adversarial test shapes.

Examples

Example 1
Input
levels = 1
Output
3
Explanation

The current level adds one beat, and the previous level echoes twice, resulting in three beats.

Example 2
Input
levels = 0
Output
1
Explanation

Only the opening strike is heard, so the total is one beat.

Example 3
Input
levels = 4
Output
31
Explanation

Four levels of echoes means a new beat plus twice the total experience of level three, producing thirty-one beats.

Algorithm Flow

Recommendation Algorithm Flow for Festival Drum Echoes - Budibadu
Recommendation Algorithm Flow for Festival Drum Echoes - Budibadu

Best Answers

java
import java.util.Arrays;
class Solution {
    public boolean drum_pattern(Object nums) {
        int[] arr = (int[]) nums;
        if (arr.length < 2 || arr.length % 2 != 0) {
            return false;
        }
        int h = arr.length / 2;
        return Arrays.equals(Arrays.copyOfRange(arr, 0, h), Arrays.copyOfRange(arr, h, arr.length));
    }
}