Template Variable Expansion
Problem statement
You are given key-value mappings and a source string. Any substring inside a pair of percent signs, such as %key%, should be treated as a key and replaced by its mapped value.
A mapped value may itself contain another key placeholder, so replacements may need to be resolved recursively.
Examples
Example 1
mappings = [["x","%y%/home"],["y","user"]]source = "/%x%/docs"return = "/user/home/docs"%x% expands to %y%/home, and %y% expands to user.
The source shared the rule but did not include this exact sample. FastPrep added this small example so the behavior can be checked directly.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 1 more worked example, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.