Code Logo

River Brightening Signal

Published atDate not available
Easy 0 views
Like0

This challenge becomes much easier once you know exactly what to keep, change, or count. In River Brightening Signal, you are trying to work toward the right number by following one clear idea.

Calculate river brightening signal 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 stations = 2, the answer is 7. The second station adds a lantern and mirrors the earlier lights twice. Another example is stations = 4, which gives 31. Four stations maintain the rule, producing thirty-one bright signals.

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

The second station adds a lantern and mirrors the earlier lights twice.

Example 2
Input
stations = 4
Output
31
Explanation

Four stations maintain the rule, producing thirty-one bright signals.

Example 3
Input
stations = 0
Output
1
Explanation

Only the first beacon is lit.

Algorithm Flow

Recommendation Algorithm Flow for River Brightening Signal
Recommendation Algorithm Flow for River Brightening Signal

Best Answers

java
class Solution {
    public int calculate_max_brightness(int[] signals) {
        if (signals.length == 0) return 0;
        int maxSoFar = signals[0], currentMax = signals[0];
        for (int i = 1; i < signals.length; i++) {
            currentMax = Math.max(signals[i], currentMax + signals[i]);
            maxSoFar = Math.max(maxSoFar, currentMax);
        }
        return maxSoFar;
    }
}