Code Logo

Lantern Pattern Paths

Published atDate not available
Easy 0 views
Like0

Picture a lantern puzzle where each step matters. In Lantern Pattern Paths, you are trying to work toward the right list by following one clear idea.

This problem feels a bit like a maze or map challenge. You need to think about how moves, paths, or links work together. Some places may still connect nicely, while others may be blocked or no longer fit the rule. The answer comes from following those connections carefully.

For example, if the input is base = "Pause by the willow.", markers = [], the answer is ["Pause by the willow."]. Example with input: base = "Pause by the willow.", markers = [] Another example is base = "Listen for distant bells.", markers = ["Golden Spine", "Silver Veil"], which gives ["Enter Golden Spine", "Enter Silver Veil", "Listen for distant bells.", "Mirror Silver Veil", "Listen for distant bells.", "Exit Silver Veil", "Mirror Golden Spine", "Enter Silver Veil", "Listen for distant bells.", "Mirror Silver Veil", "Listen for distant bells.", "Exit Silver Veil", "Exit Golden Spine"]. Example with input: base = "Listen for distant bells.", markers = ["Go

This is a friendly practice problem, but it still rewards careful reading. The key is keeping track of where you can move and which routes still follow the rule.

Example Input & Output

Example 1
Input
base = "Pause by the willow.", markers = []
Output
["Pause by the willow."]
Explanation

Example with input: base = "Pause by the willow.", markers = []

Example 2
Input
base = "Listen for distant bells.", markers = ["Golden Spine", "Silver Veil"]
Output
["Enter Golden Spine", "Enter Silver Veil", "Listen for distant bells.", "Mirror Silver Veil", "Listen for distant bells.", "Exit Silver Veil", "Mirror Golden Spine", "Enter Silver Veil", "Listen for distant bells.", "Mirror Silver Veil", "Listen for distant bells.", "Exit Silver Veil", "Exit Golden Spine"]
Explanation

Example with input: base = "Listen for distant bells.", markers = ["Go

Example 3
Input
base = "Pause by the willow.", markers = ["Azure Bridge"]
Output
["Enter Azure Bridge", "Pause by the willow.", "Mirror Azure Bridge", "Pause by the willow.", "Exit Azure Bridge"]
Explanation

Example with input: base = "Pause by the willow.", markers = ["Azure B

Algorithm Flow

Recommendation Algorithm Flow for Lantern Pattern Paths
Recommendation Algorithm Flow for Lantern Pattern Paths

Best Answers

java
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;
    }
}