BudiBadu Logo

Terraced Shell Count

Array Easy 0 views
Like30

The Terraced Shell Parade in Luminara Cove is a twilight ritual where polished shells are arranged along carved ledges. It begins with a single shell. For each additional terrace, the stewards add four guiding shells, and then the entire arrangement from the previous level is echoed twice as it reflects across the lagoon. Your task in Terraced Shell Count is to compute the total number of shells visible once all terraces are prepared.

The "secret sauce" here is a Doubling Recurrence. If the number of tiers is zero, only the first shell is shown. For every higher tier, the total follows the formula: Total = 2 * (Previous Total) + 4. This reflects how the hillside seems to breathe as the glow mirrors across the water while new beacons are set. You must return an integer representing the final count of glowing shells once the procession is ready. It’s a hypnotic pattern that turns a simple ritual into a stunning display of light!

Examples

Example 1
Input
tiers = 3
Output
36
Explanation

Three additional terraces mean another guiding shell plus twin reflections of everything from tier two.

Example 2
Input
tiers = 0
Output
1
Explanation

Only the original shell is shown.

Example 3
Input
tiers = 1
Output
6
Explanation

The new terrace adds one guiding shell and mirrors the earlier display twice.

Algorithm Flow

Recommendation Algorithm Flow for Terraced Shell Count - Budibadu
Recommendation Algorithm Flow for Terraced Shell Count - Budibadu

Best Answers

java
import java.util.*;
class Solution {
    public int calculate_shell_count(Object shell) {
        if (shell instanceof Integer) return (int) shell;
        if (shell instanceof List) {
            int total = 0;
            for (Object item : (List) shell) total += calculate_shell_count(item);
            return total;
        }
        return 0;
    }
}