FastPrepTemplate Variable Expansion

Template Variable Expansion

Google logoGoogle● MediumFULLTIMEONSITE INTERVIEW

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.

The problem statement continues
Pro

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.

FastPrep Pro
Reported in 1 Google interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
See Google hiring insights
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week