Windborne Lantern Parade
This problem feels like a little puzzle you can solve one step at a time. In Windborne Lantern Parade, you are trying to work toward the right number by following one clear idea.
Calculate windborne lantern parade 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 tiers = 5, the answer is 63. Five tiers follow the ritual, filling the sky with sixty-three lanterns. Another example is tiers = 3, which gives 15. The third tier adds a lantern and repeats the earlier tiers twice.
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
Five tiers follow the ritual, filling the sky with sixty-three lanterns.
The third tier adds a lantern and repeats the earlier tiers twice.
Only the first lantern glider is airborne.
Algorithm Flow
Solution Approach
This problem follows the same style of repeating growth as other pattern challenges. Each tier adds one lantern and repeats the earlier tiers twice, so the total at any tier depends directly on the total from the tier before it.
The rule is: the new total equals 1 + 2 * (previous total). We can simulate this easily with a loop that runs once for each tier, keeping a running total.
We begin with a single lantern, then update the total for every tier:
The important line is result = 1 + 2 * result. Each pass takes the current total, doubles it (the repeated earlier tiers), and adds one for the new lantern.
Let us trace tiers = 3. We start with result = 1. After the first tier, result = 1 + 2 * 1 = 3. After the second, result = 1 + 2 * 3 = 7. After the third, result = 1 + 2 * 7 = 15. That matches the expected answer of 15.
This is efficient because it needs exactly tiers steps. The time complexity is O(tiers) and the space complexity is O(1), as we only track a single running value.
Best Answers
class Solution {
public int windborne_lantern_parade(int tiers) {
int result = 1;
for (int i = 0; i < tiers; i++) {
result = 1 + 2 * result;
}
return result;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
