BudiBadu Logo

Starlight Lantern Chain

Array Easy 28 views
Like6

Each evening on Lyris Bluff, keepers line the cliffside with silver lanterns. The ceremony starts with a single lantern. A herald then announces the number of Tiers to follow. Each new tier adds a fresh guiding lantern, while wind-polished mirrors reflect every lantern from the previous tier twice over. In Starlight Lantern Chain, your task is to find the total lanterns visible when the ceremony concludes.

The "secret sauce" here is Recursive Doubling. For each tier i, the total count is calculated as: 1 + (2 * total_from_tier_i-1). If tiers is zero, only the initial lantern is visible (result: 1). This pattern creates two rivers of light that cast twin reflections down the stone. By the time the final tier is secured, the count has grown in a predictable, stable sequence of tiered light. Return the total count as a single integer, ensuring the sailors offshore can rely on the radiance to guide them home safely! Following this ritual literally reveals the beautiful geometry hidden in the glow.

Examples

Example 1
Input
tiers = 2
Output
7
Explanation

The second tier adds a lantern and doubles the earlier glow.

Example 2
Input
tiers = 0
Output
1
Explanation

Only the initial lantern shines.

Example 3
Input
tiers = 3
Output
15
Explanation

Three tiers preserve the pattern, revealing fifteen lanterns in total.

Algorithm Flow

Recommendation Algorithm Flow for Starlight Lantern Chain - Budibadu
Recommendation Algorithm Flow for Starlight Lantern Chain - Budibadu

Best Answers

java
class Solution {
    public int find_longest_increasing_chain(int[] nums) {
        if (nums.length == 0) return 0;
        int maxLen = 1, current = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i-1]) current++;
            else current = 1;
            maxLen = Math.max(maxLen, current);
        }
        return maxLen;
    }
}