PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Waymo

Implement nested template string substitution

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of string processing, dependency resolution, recursive expansion, cycle detection, and efficiency techniques such as memoization for nested template substitution.

  • easy
  • Waymo
  • Coding & Algorithms
  • Data Scientist

Implement nested template string substitution

Company: Waymo

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Onsite

You are given a dictionary (map) from keys to string templates. Templates may reference other keys using placeholders of the form `%KEY%`. Example dictionary: - `X -> "a"` - `Y -> "b"` - `Z -> "%X% and %Y%"` Given an input string that may also contain placeholders (e.g., `"%X% and %Z%"`), output the fully substituted string. For the example above: - Input: `"%X% and %Z%"` - Output: `"a and a and b"` ### Requirements / edge cases - Placeholders can be **nested** (a key can reference other keys). - Multiple occurrences of the same placeholder may appear. - Define how you handle: - Missing keys (e.g., `%W%` not in dictionary) - Cycles (e.g., `A -> "%B%"`, `B -> "%A%"`) - Aim for efficient time complexity (avoid repeatedly expanding the same key).

Quick Answer: This question evaluates understanding of string processing, dependency resolution, recursive expansion, cycle detection, and efficiency techniques such as memoization for nested template substitution.

Related Interview Questions

  • Expand Nested Repetition Expressions - Waymo (medium)
  • Find Shortest Paths to Target Nodes - Waymo (medium)
  • Implement Safe Average Function - Waymo (medium)
  • Serialize Expression Tree Minimizing Parentheses - Waymo (medium)
  • Find Shortest Knight Path - Waymo (medium)
Waymo logo
Waymo
Jan 17, 2026, 12:00 AM
Data Scientist
Onsite
Coding & Algorithms
13
0
Loading...

You are given a dictionary (map) from keys to string templates. Templates may reference other keys using placeholders of the form %KEY%.

Example dictionary:

  • X -> "a"
  • Y -> "b"
  • Z -> "%X% and %Y%"

Given an input string that may also contain placeholders (e.g., "%X% and %Z%"), output the fully substituted string.

For the example above:

  • Input: "%X% and %Z%"
  • Output: "a and a and b"

Requirements / edge cases

  • Placeholders can be nested (a key can reference other keys).
  • Multiple occurrences of the same placeholder may appear.
  • Define how you handle:
    • Missing keys (e.g., %W% not in dictionary)
    • Cycles (e.g., A -> "%B%" , B -> "%A%" )
  • Aim for efficient time complexity (avoid repeatedly expanding the same key).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Waymo•More Data Scientist•Waymo Data Scientist•Waymo Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.