Code Logo

Celestial Skyline Layout

Published atDate not available
Easy 0 views
Like0

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

Build recursive skyline layout structure 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 blueprint = 4, the answer is 1. Example with input: blueprint = 4 Another example is blueprint = {"base": {"base": 5, "steps": [1]}, "steps": [2, 3]}, which gives 8. Example with input: blueprint = {"base": {"base": 5, "steps": [1]}, "s

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
blueprint = 4
Output
1
Explanation

Example with input: blueprint = 4

Example 2
Input
blueprint = {"base": {"base": 5, "steps": [1]}, "steps": [2, 3]}
Output
8
Explanation

Example with input: blueprint = {"base": {"base": 5, "steps": [1]}, "s

Example 3
Input
blueprint = {"base": 4, "steps": [2]}
Output
2 (either use only the height-4 tower, or add a mirrored tower of height 6)
Explanation

Example with input: blueprint = {"base": 4, "steps": [2]}

Algorithm Flow

Recommendation Algorithm Flow for Celestial Skyline Layout
Recommendation Algorithm Flow for Celestial Skyline Layout

Best Answers

java
import java.util.*;

class Solution {
    private static final int MOD = 1000000007;

    public int count_valid_skylines(Object blueprint) {
        if (blueprint instanceof Number) {
            return 1;
        }
        Map<String, Object> fork = (Map<String, Object>) blueprint;
        long baseCount = count_valid_skylines(fork.get("base"));
        List<?> steps = (List<?>) fork.get("steps");
        int k = (steps != null) ? steps.size() : 0;
        
        long pow2k = 1;
        long b = 2;
        while (k > 0) {
            if (k % 2 == 1) pow2k = (pow2k * b) % MOD;
            b = (b * b) % MOD;
            k /= 2;
        }
        
        return (int) ((baseCount * pow2k) % MOD);
    }
}