BudiBadu Logo

Ember Nest Flames

Array Easy 3 views
Like21

In the Emberfold Valley, villagers close the market by lighting a communal hearth. The ritual begins with one glowing coal. For each additional "ember ring" announced by the crier, firekeepers lay a fresh coal to mark the boundary, and every spark from the previous ring is echoed threefold by carefully angled mirrors. Your task in Ember Nest Flames is to determine the total number of glowing embers visible after the final ring settles.

The "secret sauce" here is a Linear Recurrence. If the number of rings is zero, only the original coal shines. For any higher value, the total follows the pattern: Total = 1 + (Previous Total * 3). This reflects how the light from below blooms exactly three times over in every direction. No shortcuts are allowed; the elders believe this constant ratio wards off sudden storms. You must return a precise integer representing the final count of echoes and boundary coals across the mountain!

Keep the algorithm focused on one clear invariant and update path so correctness is easy to verify from left to right. This reduces accidental branching errors and helps ensure the final output stays consistent with the problem contract across random and adversarial test shapes.

Examples

Example 1
Input
rings = 0
Output
1
Explanation

Only the first coal remains.

Example 2
Input
rings = 2
Output
85
Explanation

The second ring adds a boundary coal and multiplies the previous glow fourfold, for a total of eighty-five embers.

Example 3
Input
rings = 4
Output
1365
Explanation

Four extra rings mean the latest coal plus four times the entire light from ring three.

Algorithm Flow

Recommendation Algorithm Flow for Ember Nest Flames - Budibadu
Recommendation Algorithm Flow for Ember Nest Flames - Budibadu

Best Answers

java
import java.util.*;
class Solution {
    public int calculate_nest_glow(Object nest) {
        if (nest instanceof Integer) return (int) nest;
        if (nest instanceof List) {
            int total = 0;
            for (Object item : (List) nest) {
                total += calculate_nest_glow(item);
            }
            return total;
        }
        return 0;
    }
}