Template Variable Expansion

Asked at GoogleOnsite

Reported by the problem's creator, not verified

A template engine fills in %key% placeholders. Template(mappings) is built once from a list of [key, value] pairs. render(source) returns source with its placeholders filled in, or the string "ERROR" when it cannot. Every render call is independent: an "ERROR" result says nothing about later calls.

Examples

  1. Example 1

    Input: init = [[["user","ada"],["dir","docs"],["a","x"],["b","y"]]], operations = [["render",["/home/%user%/%dir%/%user%.txt"]],["render",["no placeholders"]],["render",["%a%-%b%"]],["render",["%user%"]]]

    Output: ["/home/ada/docs/ada.txt","no placeholders","x-y","ada"]

    Explanation: Each %key% is replaced by its value, and a key may appear more than once. A source with no placeholders is returned unchanged.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.