BudiBadu Logo
00:00

Echoing Story Weaver

Recursion Medium 0 views

Every solstice in Alderaan Hollow, a storyteller known as the Echo Weaver guides the village through a layered recital. The recital begins with a single legend sentence that marks the heart of the tale. Then a chorus of apprentices repeats the pattern for each surrounding generation, wrapping the core with refrains that honor mentors and descendants. The weaver insists that each layer has its own introduction and epilogue so families can follow how the story winds back to the present day.

The ritual follows a strict rhythm. To build a new layer, the weaver first speaks a sentence announcing who is retelling the story, then invites the previous layer to echo in full, and finally closes with a sentence explaining how the current voice hands the tale forward. Villagers say the structure keeps the legends alive without losing nuance. When no more layers remain, the weaver speaks only the base legend and the recital ends.

The governor of Alderaan Hollow wants a program that produces the exact narration the Echo Weaver expects. You are given two strings: base, the core sentence, and voices, an array of narrator names ordered from the nearest voice outward. Return a single string representing the full recital with newline separators, using the rule above: each name contributes an intro line ("{name} echoes:"), then the complete narration of the inner voices, then a closing line ("{name} concludes."). The base layer is the base sentence itself with no extra lines.

Assume voices may be empty, in which case return only base. Otherwise, process voices recursively from first to last, so the first name is closest to the core. Preserve line breaks exactly as described.

Example 1:

Input: base = "The hearth keeps its promise.", voices = []
Output:
The hearth keeps its promise.

Example 2:

Input: base = "The hearth keeps its promise.", voices = ["Mira", "Orin"]
Output:
Mira echoes:
Orin echoes:
The hearth keeps its promise.
Orin concludes.
Mira concludes.

Example 3:

Input: base = "A river always remembers.", voices = ["Sela", "Varo", "Nyx"]
Output:
Sela echoes:
Varo echoes:
Nyx echoes:
A river always remembers.
Nyx concludes.
Varo concludes.
Sela concludes.

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.

BudiBadu Logo

Echoing Story Weaver

Recursion Medium 0 views

Every solstice in Alderaan Hollow, a storyteller known as the Echo Weaver guides the village through a layered recital. The recital begins with a single legend sentence that marks the heart of the tale. Then a chorus of apprentices repeats the pattern for each surrounding generation, wrapping the core with refrains that honor mentors and descendants. The weaver insists that each layer has its own introduction and epilogue so families can follow how the story winds back to the present day.

The ritual follows a strict rhythm. To build a new layer, the weaver first speaks a sentence announcing who is retelling the story, then invites the previous layer to echo in full, and finally closes with a sentence explaining how the current voice hands the tale forward. Villagers say the structure keeps the legends alive without losing nuance. When no more layers remain, the weaver speaks only the base legend and the recital ends.

The governor of Alderaan Hollow wants a program that produces the exact narration the Echo Weaver expects. You are given two strings: base, the core sentence, and voices, an array of narrator names ordered from the nearest voice outward. Return a single string representing the full recital with newline separators, using the rule above: each name contributes an intro line ("{name} echoes:"), then the complete narration of the inner voices, then a closing line ("{name} concludes."). The base layer is the base sentence itself with no extra lines.

Assume voices may be empty, in which case return only base. Otherwise, process voices recursively from first to last, so the first name is closest to the core. Preserve line breaks exactly as described.

Example 1:

Input: base = "The hearth keeps its promise.", voices = []
Output:
The hearth keeps its promise.

Example 2:

Input: base = "The hearth keeps its promise.", voices = ["Mira", "Orin"]
Output:
Mira echoes:
Orin echoes:
The hearth keeps its promise.
Orin concludes.
Mira concludes.

Example 3:

Input: base = "A river always remembers.", voices = ["Sela", "Varo", "Nyx"]
Output:
Sela echoes:
Varo echoes:
Nyx echoes:
A river always remembers.
Nyx concludes.
Varo concludes.
Sela concludes.

00:00
Loading editor...
Test Results

Run your code to see test results

Click the Submit button to execute your solution

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.