BudiBadu Logo

Coral Pulse Count

Array Easy 7 views
Like9

In the Lumina Reef, marine biologists track the "pulse" of different coral sections recorded as integers. Your task in Coral Pulse Count is to take an array of pulse readings and return a new array where the pulses are sorted in ascending order. This helps spotting health patterns at a glance!

The "secret sauce" is Non-Destructive Sorting. You must return a brand-new array, leaving the original sensor log untouched for archival. The pulse readings can include duplicates for stable sections and negative values for "dormant" areas. Your routine must preserve every single entry, merely rearranging them from lowest to highest. If the reef is already orderly, just return a clean, sorted copy. This simple transformation turns a chaotic log into a professional data summary for the research team instantly!

If sorting is part of the strategy, do it intentionally as a preprocessing step to simplify downstream logic such as merging, ordering, or comparison. After sorting, keep output semantics precise: preserve expected structure, avoid dropping valid entries, and ensure tied cases still follow deterministic order rules.

Examples

Example 1
Input
layers = 1
Output
1
Explanation

The first ripple adds one pulse and repeats the earlier glow three times.

Example 2
Input
layers = 3
Output
4
Explanation

Three layers maintain the rule, producing forty pulses when the celebration ends.

Example 3
Input
layers = 0
Output
40
Explanation

Only the initial coral emits light.

Algorithm Flow

Recommendation Algorithm Flow for Coral Pulse Count - Budibadu
Recommendation Algorithm Flow for Coral Pulse Count - Budibadu

Best Answers

java
class Solution {
    public int coral_pulse_count(Object layers) {
        int n = layers instanceof Integer ? (int) layers : 0;
        if (n == 0) return 1;
        int pulses = 1;
        for (int i = 0; i < n; i++) {
            pulses = 1 + 3 * pulses;
        }
        return pulses;
    }
}