Code Logo

Mirror Lantern Glow

Published atDate not available
Easy 0 views
Like0

This problem feels like a little puzzle you can solve one step at a time. In Mirror Lantern Glow, you are trying to work toward the right number by following one clear idea.

Calculate mirror lantern expansion pattern A good way to think about it is to first understand what goes in, then what rule you must follow, and finally what shape the answer should have.

For example, if the input is layers = 2, the answer is 7. The new layer adds one lantern, and the previous layers contribute twice their earlier total, giving seven perceived lanterns. Another example is layers = 0, which gives 1. Only the central lantern is visible, so the total count is one.

This is a friendly practice problem, but it still rewards careful reading. The key is understanding the rule clearly and then applying it carefully.

One helpful habit is to say the rule out loud in your own words before you start solving. If you can explain what counts, what changes, and what the final answer should look like, you are already much closer to the right solution.

Example Input & Output

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
Recommendation Algorithm Flow for Mirror Lantern Glow

Best Answers

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