BudiBadu Logo

Harbor Tide Chants

Array Easy 1 views
Like27

In the Seafarer’s Cove, harbor masters recite "Tide Chants" to set the daily work rhythm. The ritual begins with a single bell toll. For each new tide level, the master toll a fresh bell, and then every chime from the prior level is echoed threefold by the harbor's natural tunnels. Your task in Harbor Tide Chants is to calculate the total number of chime echoes audible once the final tide level is reached.

The "secret sauce" here is a Linear Recurrence. If the number of tide levels is zero, only the initial bell sounds. For any higher level, the total follows the pattern: Total = 1 + (Previous Total * 3). This reflects how the cove’s acoustics multiply the sound exactly three times over for every new beacon. You must return an integer representing the final count of echoes. It’s a rhythmic, recursive challenge that turns a beautiful nautical tradition into a practical exercise in exponential growth modeling!

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
rolls = 2
Output
13
Explanation

The second roll adds a verse and repeats the earlier chorus three times.

Example 2
Input
rolls = 0
Output
1
Explanation

Only the caller sings, so one verse is heard.

Example 3
Input
rolls = 4
Output
121
Explanation

Four rolls follow the rule, ending with one guiding verse plus triple the sound of roll three.

Algorithm Flow

Recommendation Algorithm Flow for Harbor Tide Chants - Budibadu
Recommendation Algorithm Flow for Harbor Tide Chants - Budibadu

Best Answers

java
class Solution {
    public int harbor_tide_chants(int rolls) {
        int result = 1;
        for (int i = 0; i < rolls; i++) {
            result = 1 + 3 * result;
        }
        return result;
    }
}