3481. Apply Substitutions
ArrayHash TableStringDepth-First SearchBreadth-First SearchGraph TheoryTopological Sort
Hints
Hint 1
Build a dependency graph where each key is a node, and add an edge from key
X to key Y if the replacement value for Y contains the placeholder %X%. Then perform a topological sort to determine a valid order for substitution.Hint 2
Process the keys in the topologically sorted order by replacing placeholders in each replacement value with its fully expanded value. Finally, substitute the placeholders in the text using these computed values.
Preparing judge…