Code Logo

Ember Glyph Mosaic

Published atDate not available
Easy 0 views
Like0

This problem feels like a little puzzle you can solve one step at a time. In Ember Glyph Mosaic, you are trying to work toward the right list by following one clear idea.

Build glyph mosaic with expanding rings 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 = ["*"], bands = ["North"], the answer is ["North^", "*", "vNorth", "*"]. Example with input: base = ["*"], bands = ["North"] Another example is base = ["*"], bands = [], which gives ["*"]. Example with input: base = ["*"], bands = []

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

One helpful habit is to say the rule out loud in your own words before you start solving. If you can explain what counts, what changes, and what the final answer should look like, you are already much closer to the right solution.

Example Input & Output

Example 1
Input
base = ["*"], bands = ["North"]
Output
["North^", "*", "vNorth", "*"]
Explanation

Example with input: base = ["*"], bands = ["North"]

Example 2
Input
base = ["*"], bands = []
Output
["*"]
Explanation

Example with input: base = ["*"], bands = []

Example 3
Input
base = [".o.", "ooo"], bands = ["Amber", "Quartz"]
Output
["Amber^", "Quartz^", ".o.", "ooo", "vQuartz", ".o.", "ooo", "Amber^", "Quartz^", ".o.", "ooo", "vQuartz", ".o.", "ooo", "vAmber", "Quartz^", ".o.", "ooo", "vQuartz", ".o.", "ooo"]
Explanation

Example with input: base = [".o.", "ooo"], bands = ["Amber", "Quartz"]

Algorithm Flow

Recommendation Algorithm Flow for Ember Glyph Mosaic
Recommendation Algorithm Flow for Ember Glyph Mosaic

Best Answers

java
import java.util.*;

class Solution {
    public String[] ember_glyph_mosaic(String[] base, String[] bands) {
        return build(Arrays.asList(base), bands, 0).toArray(new String[0]);
    }
    
    private List<String> build(List<String> current, String[] bands, int idx) {
        if (idx >= bands.length) return new ArrayList<>(current);
        String marker = bands[idx];
        List<String> inner = build(current, bands, idx + 1);
        List<String> result = new ArrayList<>();
        result.add(marker + "^");
        result.addAll(inner);
        result.add("v" + marker);
        result.addAll(inner);
        return result;
    }
}