Code Logo

Glacier Signal Fires

Published atDate not available
Easy 0 views
Like0

Imagine signal fires spreading across icy mountain ridges in a repeating pattern. At the very beginning, there is only one fire. Then each new ridge makes the pattern grow using the total from the stage before it.

Your job is to calculate how many fires are burning after a given number of ridges. This is a growth-pattern problem, so the answer comes from understanding how one stage changes into the next. The examples show that the total grows quickly, which means each new ridge is adding much more than just one extra fire.

For example, when ridges = 0, the answer is 1. When ridges = 2, the answer is 13. By the time ridges = 4, the total reaches 121. Those jumps show that the pattern is being built from the previous result again and again.

The important part is finding the rule that links each ridge count to the next one. Once you understand that growth rule, you can compute the total for any valid input.

Example Input & Output

Example 1
Input
ridges = 4
Output
121
Explanation

Four responding ridges keep the rule, ending with one guiding fire plus triple the blaze from ridge three.

Example 2
Input
ridges = 2
Output
13
Explanation

The second ridge adds a beacon and repeats the earlier lights three times.

Example 3
Input
ridges = 0
Output
1
Explanation

Only the opening signal burns.

Algorithm Flow

Recommendation Algorithm Flow for Glacier Signal Fires
Recommendation Algorithm Flow for Glacier Signal Fires

Best Answers

java
class Solution {
    public int glacier_signal_fires(Object input) {
        int ridges = (int) input;
        return (int)((Math.pow(3, ridges + 1) - 1) / 2);
    }
}