Code Logo

Echoing Story Weaver

Published atDate not available
Easy 0 views
Like0

You can think of this as a small game with a very specific goal. In Echoing Story Weaver, you are trying to work toward the right answer by following one clear idea.

Weave layered echo story 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 base = "A river always remembers.", voices = ["Sela", "Varo", "Nyx"], the answer is . Example with input: base = "A river always remembers.", voices = ["Sel Another example is base = "The hearth keeps its promise.", voices = [], which gives . Example with input: base = "The hearth keeps its promise.", voices = [

This is a friendly practice problem, but it still rewards careful reading. The key is understanding the rule clearly and then applying it carefully.

Example Input & Output

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
Recommendation Algorithm Flow for Echoing Story Weaver

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();
    }
}