Aurora Feather Lights
You can think of this as a small game with a very specific goal. In Aurora Feather Lights, you are trying to work toward the right number by following one clear idea.
Calculate feather lantern sequence growth 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 sweeps = 4, the answer is 341. Four sweeps follow the rule, producing three hundred forty-one shimmering feathers. Another example is sweeps = 0, which gives 1. Only the opening feather lantern glows.
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
Four sweeps follow the rule, producing three hundred forty-one shimmering feathers.
Only the opening feather lantern glows.
The second sweep adds one feather and echoes the earlier light four times.
Algorithm Flow
Solution Approach
This problem is about a growing feather pattern where each sweep adds the next power of four. Starting with a single opening lantern, every sweep contributes 4^i new feathers, so the total is the sum of a geometric series with a ratio of 4.
The cleanest way to compute this is to loop from 0 up to sweeps and add 4^i each time. Alternatively, we can use the closed form of the geometric series, but the loop is simple and easy to verify.
Here is the implementation:
The loop runs from i = 0 to i = sweeps inclusive, adding 4^i to the running total. Each iteration represents one more sweep of the growing pattern.
Let us trace sweeps = 4. The sum is 4^0 + 4^1 + 4^2 + 4^3 + 4^4 = 1 + 4 + 16 + 64 + 256 = 341, which matches the expected answer. When sweeps = 0, only 4^0 = 1 is added, so the answer is 1.
We could also recognize this as the closed form (4^(sweeps + 1) - 1) / 3, which gives the same result in constant time. For example, with sweeps = 4, that is (1024 - 1) / 3 = 341.
The loop version runs in O(sweeps) time and O(1) space, while the closed form is O(1) in both.
Best Answers
class Solution {
public int aurora_feather_lights(int sweeps) {
int total = 0;
for (int i = 0; i <= sweeps; i++) {
total += (int) Math.pow(4, i);
}
return total;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
