BudiBadu Logo

Mirror Lantern Glow

Array Easy 0 views
Like14

In Crescent Harbor, caretakers sustain a corridor of glasswater with reflection layers. Each layer transforms the sensation of the central lantern into a flaring ring of light. Your task in Mirror Lantern Glow is to model the ceremonial count of perceived lanterns as the reflection layers deepen. Planners use this to predict exactly how bright the walkway will appear to visitors.

The "secret sauce" here is a Doubling Reflection Pattern. For every new layer, you add one new tangible lantern, and then every existing lantern (and its reflection) is doubled across the mirrored panels. If layers is zero, only the central lantern shines (result: 1). This recursive doubling captures the symmetrical bloom of light that signaled sailors home through the fog. Return the final count as a single integer, ensuring the stewards can build the same cascade of light every festival night! Precision helps maintain the history and mood of the Crescent Harbor tradition beautifully.

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

The new layer adds one lantern, and the previous layers contribute twice their earlier total, giving seven perceived lanterns.

Example 2
Input
layers = 0
Output
1
Explanation

Only the central lantern is visible, so the total count is one.

Example 3
Input
layers = 5
Output
31
Explanation

Five layers mean a fresh lantern plus mirrored echoes of all earlier layers, leading to thirty-one points of light.

Algorithm Flow

Recommendation Algorithm Flow for Mirror Lantern Glow - Budibadu
Recommendation Algorithm Flow for Mirror Lantern Glow - Budibadu

Best Answers

java
class Solution {
    public int mirror_lantern_glow(Object input) {
        int layers = (int) input;
        return (int) Math.pow(2, layers + 1) - 1;
    }
}