BudiBadu Logo

Echoing Story Weaver

Array Easy 3 views
Like8

Every solstice in Alderaan Hollow, the Echo Weaver leads a layered recital. The tale begins with a base legend at its heart, wrapped in refrains from generations of apprentices. Each new voice adds their own introduction and epilogue, creating a beautifully symmetrical narrative. Your task in Echoing Story Weaver is to produce the exact multi-line script for this ceremony.

The "secret sauce" here is Recursive String Building. Each voice in the voices array (from nearest to furthest) contributes an intro line ("{name} echoes:") and a closing line ("{name} concludes."). These wrap around the core legend and all the inner echoes. The result is a strictly ordered script with newline separators. If no voices are present, the weaver simply speaks the base legend alone. This recursive pattern ensures that every family can follow the story correctly as it winds back to the present day.

This is a classic recursion problem that focuses on formatting and sequence. It’s the gold standard for understanding how recursive calls can "wrap" content to create complex, nested structures!

Examples

Example 1
Input
base = "A river always remembers.", voices = ["Sela", "Varo", "Nyx"]
Output
Explanation

Example with input: base = "A river always remembers.", voices = ["Sel

Example 2
Input
base = "The hearth keeps its promise.", voices = []
Output
Explanation

Example with input: base = "The hearth keeps its promise.", voices = [

Example 3
Input
base = "The hearth keeps its promise.", voices = ["Mira", "Orin"]
Output
Explanation

Example with input: base = "The hearth keeps its promise.", voices = [

Algorithm Flow

Recommendation Algorithm Flow for Echoing Story Weaver - Budibadu
Recommendation Algorithm Flow for Echoing Story Weaver - Budibadu

Best Answers

java
import java.util.*;

class Solution {
    public String echoing_story_weaver(String base, String[] voices) {
        if (voices.length == 0) return base;
        StringBuilder sb = new StringBuilder();
        for (String name : voices) {
            sb.append(name).append(" echoes:
");
        }
        sb.append(base);
        for (int i = voices.length - 1; i >= 0; i--) {
            sb.append("
").append(voices[i]).append(" concludes.");
        }
        return sb.toString();
    }
}