River Brightening Signal
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
The second station adds a lantern and mirrors the earlier lights twice.
Four stations maintain the rule, producing thirty-one bright signals.
Only the first beacon is lit.
Algorithm Flow

Best Answers
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;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
