Code Logo

Moonlit Orchid Bloom

Published atDate not available
Easy 0 views
Like0

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

Calculate orchid bloom pattern recursively 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 rings = 5, the answer is 63. Five rings follow the pattern, yielding sixty-three glowing orchids. Another example is rings = 0, which gives 1. Only the central orchid opens.

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
rings = 5
Output
63
Explanation

Five rings follow the pattern, yielding sixty-three glowing orchids.

Example 2
Input
rings = 0
Output
1
Explanation

Only the central orchid opens.

Example 3
Input
rings = 2
Output
7
Explanation

The second ring adds one blossom and reflects the earlier blooms twice.

Algorithm Flow

Recommendation Algorithm Flow for Moonlit Orchid Bloom
Recommendation Algorithm Flow for Moonlit Orchid Bloom

Best Answers

java
class Solution {
    public int calculate_orchid_height(int n) {
        if (n == 0) return 0;
        if (n == 1) return 1;
        int[] dp = new int[n + 1];
        dp[1] = 1;
        for (int i = 2; i <= n; i++) {
            dp[i] = i + dp[(i-2)];
        }
        return dp[n];
    }
}