BudiBadu Logo

Emberstone Step Glow

Array Easy 0 views
Like1

On Emberstone Ridge, hikers ascend at twilight under the guidance of glowing step markers. The ascent begins with a single emberstone at the trailhead. Before the climb continues, the lead ranger declares how many terraces will ignite. Each terrace receives one fresh ember to mark its edge, and the stones from the previous terrace flare fourfold along volcanic ridges, tracing a ladder of light that echoes into the narrow canyon.

The rangers rely on this steady rhythm, especially during storm seasons. Once the edge ember is placed, the entire glow from the earlier terrace races along four carved channels, ensuring wanderers see every route taken before. No ranger alters the sequence; decades of safe crossings depend on the reliable pattern of one new ember and four echoes of the former terrace.

Your job is to determine how many glowing steps a hiker sees by the time the ascent reaches its final terrace. The input terraces is a non-negative integer. When terraces equals zero, only the initial ember shines. For each added terrace, include one guiding ember and four copies of the light from the prior terrace. Return the total glow count as an integer.

Example 1:

Input: terraces = 0
Output: 1
Explanation: Only the first emberstone glows.

Example 2:

Input: terraces = 2
Output: 21
Explanation: The second terrace adds one ember and mirrors the earlier route four times.

Example 3:

Input: terraces = 5
Output: 1365
Explanation: Five terraces maintain the rule, revealing a glowing path of 1365 embers.

Algorithm Flow

Recommendation Algorithm Flow for Emberstone Step Glow - Budibadu
Recommendation Algorithm Flow for Emberstone Step Glow - Budibadu

Best Answers

java
class Solution {
    public int emberstone_step_glow(int[] nums, int k, int s) {
        int total = 0;
        for (int i = 0; i <= k; i++) {
            int idx = i * s;
            if (idx < nums.length) {
                total += nums[idx];
            }
        }
        return total;
    }
}