BudiBadu Logo

Emberstone Step Glow

Array Easy 0 views
Like1

On Emberstone Ridge, hikers ascend by glowing step markers. The ascent begins with a single emberstone at the trailhead. A ranger then declares how many Terraces will ignite. Each terrace adds one fresh edge ember, while lanterns from the prior terrace flare fourfold echoing into the narrow canyon. In Emberstone Step Glow, your task is to find the total number of glowing steps seen by the final terrace.

The "secret sauce" here is Recursive Quadruple Stacking. For each terrace i, the total glow count is: 1 + (4 * total_from_terrace_i-1). If terraces is zero, only the initial trailhead ember shines (result: 1). This steady rhythm ensures safe crossings through the canyon by reusing earlier routes through four carved volcanic channels. Return the total count as a single integer, ensuring the hikers can rely on the ladder of light for every Cross! Following this reliable tradition literally reveals the reliable counting pattern hidden in the glow of the volcanic rocks.

When the task involves connectivity or route cost, build adjacency carefully and guard against revisiting stale states. Use a visited or best-distance structure to avoid repeated work, and ensure unreachable scenarios return the required fallback value instead of partial traversal results.

Examples

Example 1
Input
terraces = 2
Output
21
Explanation

The second terrace adds one ember and mirrors the earlier route four times.

Example 2
Input
terraces = 5
Output
1365
Explanation

Five terraces maintain the rule, revealing a glowing path of 1365 embers.

Example 3
Input
terraces = 0
Output
1
Explanation

Only the first emberstone glows.

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;
    }
}