BudiBadu Logo

Crystal Bell Resonance

Array Easy 0 views
Like24

Within the Cavern of Vials, soundkeepers greet travelers by ringing ceremonial crystal bells. The ritual begins with a single tone from the largest bell. A conductor then announces how many Resonance Rings follow. Each ring starts with one fresh anchor tone, while the smooth cavern walls reflect every tone from the previous ring three times! In Crystal Bell Resonance, your task is to determine the total number of tones heard by the time the final ring fades.

The "secret sauce" here is Recursive Triple Stacking. For each ring i, the total count is calculated as: 1 + (3 * total_from_ring_i-1). If rings is zero, only the initial bell is audible (result: 1). This measured swell of sound keeps the caverns stable and guides travelers through the darkness. It’s a classic geometric progression problem where you build the total layer by layer. Return the final count as a single integer so the keepers can prepare the ritual correctly! Precision ensures the music perfectly matches the cavern's natural harmony.

Examples

Example 1
Input
rings = 2
Output
13
Explanation

The second ring adds one tone and repeats the earlier resonance three times.

Example 2
Input
rings = 0
Output
1
Explanation

Only the first bell rings.

Example 3
Input
rings = 4
Output
121
Explanation

Four rings sustain the pattern, yielding one anchor tone plus triple the third ring's sound.

Algorithm Flow

Recommendation Algorithm Flow for Crystal Bell Resonance - Budibadu
Recommendation Algorithm Flow for Crystal Bell Resonance - Budibadu

Best Answers

java
class Solution {
    public int crystal_bell_resonance(int rings) {
        return ((int) Math.pow(3, rings + 1) - 1) / 2;
    }
}