PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

How do you expand nested placeholders in strings?

Last updated: Mar 29, 2026

Quick Overview

This intermediate-level Coding & Algorithms problem for Data Scientist roles evaluates string parsing and manipulation skills along with dependency resolution techniques such as recursion or graph traversal, cycle detection, and memoization.

  • medium
  • Meta
  • Coding & Algorithms
  • Data Scientist

How do you expand nested placeholders in strings?

Company: Meta

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a dictionary of string templates. Keys are identifiers like `X`, `Y`, `Z`. A template may contain placeholders of the form `%KEY%`, which should be replaced by the fully-expanded value of `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%"`), return the fully expanded string. Example: - Input: `"%X% and %Z%"` - Output: `"a and a and b"` Assumptions/requirements to clarify in your solution: - Templates can reference other templates (nested expansion). - Decide how to handle missing keys and cyclic references (e.g., `A -> "%B%"`, `B -> "%A%"`). - Provide time/space complexity for your approach.

Quick Answer: This intermediate-level Coding & Algorithms problem for Data Scientist roles evaluates string parsing and manipulation skills along with dependency resolution techniques such as recursion or graph traversal, cycle detection, and memoization.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
Meta logo
Meta
Nov 24, 2025, 12:00 AM
Data Scientist
Onsite
Coding & Algorithms
2
0

You are given a dictionary of string templates. Keys are identifiers like X, Y, Z. A template may contain placeholders of the form %KEY%, which should be replaced by the fully-expanded value of 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%"), return the fully expanded string.

Example:

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

Assumptions/requirements to clarify in your solution:

  • Templates can reference other templates (nested expansion).
  • Decide how to handle missing keys and cyclic references (e.g., A -> "%B%" , B -> "%A%" ).
  • Provide time/space complexity for your approach.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 8,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.