Lantern Pattern Paths
Designers at the Festival of Threads create riverside mazes using lantern arcs. Each design starts with a `base` walkway phrase. Curators then wrap it in multiple mirrored corridors. Your task in Lantern Pattern Paths is to generate the full usher script for this layered experience.
The "secret sauce" here is Recursive Wrapping. Each corridor (named marker) wraps around the current script with three new lines and a second pass through the inner path. For each marker, ushers recite: "Enter {marker}", the current full script, "Mirror {marker}", the script again, and finally "Exit {marker}". If markers is empty, return just the base phrase. This woven experience creates a hypnotic rhythm using a symmetrical pattern! It’s a great way to practice modeling growth through recursive string manipulation. Return an array of strings describing every phrase in the precise order guests will hear them.
When the task involves connectivity or route cost, build adjacency carefully and guard against revisiting stale states. Use a visited or best-distance structure to avoid repeated work, and ensure unreachable scenarios return the required fallback value instead of partial traversal results.
Examples
Example with input: base = "Pause by the willow.", markers = []
Example with input: base = "Listen for distant bells.", markers = ["Go
Example with input: base = "Pause by the willow.", markers = ["Azure B
Algorithm Flow

Best Answers
class Solution {
public int lantern_pattern_paths(int m, int n) {
return (int) nCr(m + n - 2, m - 1);
}
private long nCr(int n, int r) {
if (r > n) return 0;
if (r == 0 || r == n) return 1;
if (r > n / 2) r = n - r;
long res = 1;
for (int i = 1; i <= r; i++) {
res = res * (n - i + 1) / i;
}
return res;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
